Replies: 2 comments 1 reply
-
If the reported heap size is growing, it does tell you that Python is allocating memory from the operating system and not returning it. That's not necessarily wrong, though.
It seems unlikely to be related to garbage collection to me. Heap fragmentation, for instance, can cause a program to hold on to relatively large amounts of memory even when it only needs a small bit of what's on each page. If the reported heap memory is continuously growing, though, it tells me that the process is continuously requesting more memory from the OS and not freeing all of it.
That's exactly the feature that temporal flame graphs provide. If you generate a flame graph with |
Beta Was this translation helpful? Give feedback.
-
Is "heap fragmentation" you mentioned here caused by pymalloc, then I can eliminate it by setting |
Beta Was this translation helpful? Give feedback.
-
memray flamegraph --leak
is useful when you know there's a memory leak problem and you want to find out the leaking code.In my use case, I want to use memray to see whether there is a memory leak.
As we know, python memory allocator is more likely to hold the memory even after objects are destroyed, so if we only look at the memory usage of a process from outside, we always see a curve that grows slowly by time, which makes us difficult to determine whether there's actually a memory leak.
With memray we can see the behavior of a process from an internal view, which does a great help. However, I still see some limitations:
When profiling a process that I'm pretty sure there's no memory leak, I still see the heap size slowly grows by time, from the graph produced by
memray flamegraph --leak
, even after I set PYTHONMALLOC to malloc. I'm expecting to see heap size stable on this curcumstance but in fact it's not the case. I'm not sure if it's related to garbage collection, maybe memray can take garbage collection into consideration?When hunting down memory leak, I think it's more useful to produce memory allocation diffs between timestamps. In this way we can see clearly who is leaking memory. Especially when the leaked memory is relatively small compared to the "base" memory usage of a process.
Beta Was this translation helpful? Give feedback.
All reactions