[issue44310] Document that lru_cache uses hard references

Henk-Jaap Wagenaar report at bugs.python.org
Tue Jun 8 11:42:07 EDT 2021


Henk-Jaap Wagenaar <wagenaarhenkjaap at gmail.com> added the comment:

Reading this bug thread last week made me realize we had made the following error in our code:


class SomethingView():
    @functools.lru_cache()
    def get_object(self):
        return self._object


Now, as this class was instantiated for every (particular kind of) request to a webserver and this method called (a few times), the lru_cache just kept filling up and up. We had been having a memory leak we couldn't track down, and this was it.

I think this is an easy mistake to make and it was rooted, not so much in hard references though (without that though, it would have not leaked memory) but because of the fact the cache lives on the class and not the object.

----------
nosy: +cryvate

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44310>
_______________________________________


More information about the Python-bugs-list mailing list