Python Forum
Understanding tracemalloc results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understanding tracemalloc results
#1
Hello,
I'm trying to find a memory leak in my program and I'm using tracemalloc.
From my understanding, the idea of tracealloc is that since you call "start()", each time you are calling "take_snapshot()" you will get the total amount of memory allocated, and then use "compare_to" between two full dumps.
But as it seems, this is not the case, as shown in this small example:

Output:
~ ยป ipython Python 3.7.7 (default, Mar 10 2020, 15:43:33) Type 'copyright', 'credits' or 'license' for more information IPython 7.15.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import tracemalloc In [6]: tracemalloc.start() In [7]: print(tracemalloc.take_snapshot().statistics('lineno')[0]) /Users/nudler/work/vision_client/venv/lib/python3.7/site-packages/prompt_toolkit/key_binding/key_bindings.py:563: size=88.7 KiB, count=1102, average=82 B In [8]: print(tracemalloc.take_snapshot().statistics('lineno')[0]) /Users/nudler/work/vision_client/venv/lib/python3.7/site-packages/prompt_toolkit/key_binding/key_bindings.py:563: size=52.4 KiB, count=627, average=86 B
As you can see, both "size" and "count" fields for the same line got decreased in the second call for "take_snapshot()".

What am I missing? Is "take_snapshot" returns the diff from the last call? (I got similar results from my actual code, size and count got decreased between two snapshots)

Thank you very much :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,224 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to append one function1 results to function2 results SriRajesh 5 3,120 Jan-02-2020, 12:11 PM
Last Post: Killertjuh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020