Closed jessehersch closed 4 years ago
This is actually working broken working as designed, because show_growth() shows
Show the increase in peak object counts since last call.
(emphasis mine)
If you change your broken() function to create 1002 somethings in the second list, you'll see
...
------------this is broken-------------
builtins.function 1793 +1793
builtins.wrapper_descriptor 1039 +1039
builtins.dict 929 +929
builtins.builtin_function_or_method 792 +792
builtins.method_descriptor 751 +751
builtins.weakref 581 +581
builtins.tuple 544 +544
builtins.getset_descriptor 372 +372
builtins.member_descriptor 303 +303
builtins.type 145 +145
should have 1000 somethings now. first one is <__main__.Something object at 0x7f3afbb50110>
__main__.Something 1000 +1000
builtins.list 126 +1
somethings should be gone now:
should have 1000 somethings again, but we do not. first one is <__main__.Something object at 0x7f3afb9c8750>
__main__.Something 1002 +2
<__main__.Something object at 0x7f3afb9c8750>
IIRC I chose to do this because I was mostly interested in hunting memory leaks (objects that never go away), and objects where the counts go up and down all the time but never go beyond a certain fixed peak level used to produce too much noise in the output.
I wish I were rich and could hire a technical writer to make the documentation clearer...
understood. from my perspective showing the current counts is more useful, but I can implement that myself easily enough.
I didn't realize until now that it was showing peak counts, although I should have realized it since the param in growth() that takes the mutable as a default is called peak_stats
:)
actually not sure I agree that is working correctly because once 1000 somethings are created again after all have been destroyed, then delta should be +1000 again. but it's not. it's simply missing. If that's by design, ok. that behavior is strange to me though.
The delta shown is always relative to the last peak value.
the problem
show_growth() relies on the strange behavior of taking a mutable as the default value of an arg. That leads to a bug where incorrect results are returned. At least they are incorrect to my understanding. Could be my understanding is wrong though :)
See repro below.
objgraph version: 3.4.1
repro:
which produces something like this: