Such issues can make a program use too much memory, making it slow by itself as well as slowing down an entire server, or it may fail to run at all in a limited memory device such as a mobile phone.
The primary motivation for Heapy is that there has been a lack of support for the programmer to get information about the memory usage in Python programs.
Heapy provide the following feature:-
- Finds reachable and/or unreachable objects in the object heap, and collects them into special C-implemented 'nodesets'. Can get data about the objects such as their sizes and how they refer to each other.
- Uses a C library that can get data about non-standard types from extension modules, given a function table.
- Optionally uses multiple Python interpreters in the same process, so one can monitor the other transparently.
- Algebraic set operations, for example the set difference can be used to extract the objects allocated after a reference point in time.
- Various classifications of object sets, and different classifiers can be combined.
- Shortest paths to a set of objects from other objects, which can be used to find out why the objects are retained in memory.
- Requires Tk if the graphical browser is to be used.
- Can not be used with Jython or other non-C Python versions.
- A general 'glue' model provides a session context that imports modules and creates objects automatically when accessed. The glue model is not Heapy specific but is used throughout Guppy and could be used by other packages as well.
- The glue model makes it practical to have everything in Guppy being dynamically allocated in a session context, so there is no need for any global module-level variables. The modules themself are stored as usual in sys.modules but they are not modified.
Heapy has been used during development of itself and of the other parts of Guppy. It has been used to tell how much memory the parts of compound objects use, to see what could be worthwhile to optimize. It was used to find a memory leak in the Heapy profile browser, and to find out the cause, which as far as I can tell was due to a bug in a library routine.