You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately not all objects are tracked by the Python garbage collector. Specifically, "simple" objects that cannot contain references to other objects are never tracked -- these include things like str/int instances, as well as, apparently, numpy arrays.
This is actually documented, but the documentation is a bit vague: show_growth says
Count the number of instances for each type tracked by the GC.
Note that the GC does not track simple objects like int or str.
Do you have any suggestions for improving the documentation so this isn't that big of a surprise?
It may be possible to write code to count these objects with some extra effort (see issue #2), but it's non-trivial (I'd need to eliminate duplicates without artificially inflating the number of dicts/strings used while eliminating duplicates), so I cannot promise anything within a reasonable amount of time.
mgedmin
changed the title
It seems objgraph doesn't catch the object growing in a list
objgraph.show_growth() doesn't notice numpy arrays (and other non-GC-tracked types)
Jan 4, 2016
I think it is clear enough. You can't enumerate all the type that GC doesn't track. If you want you can add a function for users to determine whether a type is tracked, but I think it is more of users' own job.
If you want you can add a function for users to determine whether a type is tracked,
There's gc.istracked(), in Python 2.7 and 3.1+. Note the interesting fine print:
However, some type-specific optimizations can be present in order to suppress the garbage collector footprint of simple instances (e.g. dicts containing only atomic keys and values)
See this code:
the result is:
for the 2,3 and 4 epoch, it shows nothing growing. But it should show that the number of numpy.array grows
The text was updated successfully, but these errors were encountered: