This code is from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65333 This is under the Python Licence. It also contains spiv's code from: http://twistedmatrix.com/users/spiv/countrefs.py This is under 'MIT Licence if I'm pressed' None of this should be in day-to-day use. Feel free to document usage and improve APIs as needed.
Function | memory | Return memory usage in bytes. |
Function | resident | Return resident memory usage in bytes. |
Function | stacksize | Return stack size in bytes. |
Function | dump_garbage | show us what's the garbage about |
Function | classesWithMostRefs | Return the n ClassType objects with the highest reference count. |
Function | mostRefs | Return the n types with the highest reference count. |
Function | countsByType | Return the n types with the highest instance count in a list. |
Function | deltaCounts | Compare two references counts lists and return the increase. |
Function | printCounts | Undocumented |
Function | readCounts | Reverse of printCounts(). |
Function | logInThread | Undocumented |
Function | _VmB | Private. |
Function | _logRefsEverySecond | Undocumented |
import gc gc.enable() gc.set_debug(gc.DEBUG_LEAK)
This gives an idea of the number of objects in the system by type, since each instance will have at lest one reference to the class.
Returns | A list of tuple (count, type). |
This one uses a different algorithm than classesWithMostRefs. Instead of retrieving the number of references to each ClassType, it counts the number of objects returned by gc.get_objects() and aggregates the results by type.
Returns | A list of tuple (count, type). |
This takes a list of objects and count the number of objects by type.