2 ms·
I've used the gc module, with get_referers and get_referents, to track down various leaks. This only really helps with python-allocated object. It's trivial t
by dekhn 10y ago
I've used the gc module, with get_referers and get_referents, to track down various leaks. This only really helps with python-allocated object.
It's trivial to end up with an unexpected strong reference. Weak references are the right way to deal with cache objects, imho.
- bbernard 10y agoInteresting approach! It's hard to tell the difference between a real memory leak and Python objects being accumulated infinitely in memory - at least if we rely only on the memory use of a process. That's why we need to use either gc or objgraph as a first step.
- dom0 10y ago> Weak references are the right way to deal with cache objects, imho. Yet, I disagree ;) Whether a weakref is the correct thing to use or not depends entirely on the purpose of the cache. I often find myself using caches were weakref would not be very useful, because it would cool the cache a lot.