Hacker News new | past | comments | ask | show | jobs | submit login

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.




> 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.


Interesting 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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: