Extracting Python heap from core dump


Are there tools to analyze the Python heap from a core dump?

I’m interested in per type object statistics and the ability to navigate reference paths to diagnose memory leaks.

Best regards

If python is crashing then I would use gdb and valgrind to find the issue (assuming linux/unix).

It python is not crashing then you can use the gc module to track down most (but not all) the objects that are in the python heap.
You can write a function that creates a summary of the number of each type of object the gc knows about.

Use that function to catch the state at one point in time.
Then after running your code for a while get the new state.
Subtruct the old state’s counts from the new and you have a why to see what objects are leaking.

Using the GC module and hooking it up to a signal was my backup plan.

Nevertheless being able to inspect a core dump would be more conveniente for exploration since exporting the whole reference graph from Python would be prohibitive.

That is why I summarise the objects used.

If you are leaking instances of one class, for example, the diff of counts of objects will find it efficiently.