I have lengthy processes that may have a resource leak. How can I get a list of all instances of objects (maybe just a certain class) in my environment?
Try gc.get_objects() :
gc.get_objects()
>>> import gc >>> >>> class Foo: pass ... >>> f1 = Foo() >>> >>> [o for o in gc.get_objects() if isinstance(o, Foo)] [<__main__.Foo instance at 0x2d2288>] >>> >>> f2 = Foo() >>> >>> [o for o in gc.get_objects() if isinstance(o, Foo)] [<__main__.Foo instance at 0x2d2288>, <__main__.Foo instance at 0x2d22b0>]
There are several ways that you should combine to a large extent. I have used this module in the past to accurately verify that memory leaks
https://mg.pov.lt/objgraph/
This can cause your process to use TON more memory and be quite slow, though, depending on how you use it.
All created objects (I assume for Python itself in one module):
globals().keys() .
globals().keys()
For all those that are instances of only a particular class:
filter(lambda x: isinstance(x, some_class), globals().keys()) .
filter(lambda x: isinstance(x, some_class), globals().keys())
Source: https://habr.com/ru/post/958345/More articles:How can I rotate a sprite in Unity 4.3? - rotationvisual studio intellitrace does not work with w3wp - visual-studioMissing artifact: org.hibernate: hibernate-entitymanager: jar: 3.3.2.ga - javaIs there a way to measure direct memory usage in Java? - javaAndroid: how to save camera result in a personal file - androidPositive to use pandoc with HTML containing base64 inline images? - base64Observer pattern with threads - javaEffectively subtract a vector from a matrix (Scipy) - pythonWhat is the difference between exporting and publishing in typescript? - publicMP4 is not supported in Firefox? - html5All Articles