[New-bugs-announce] [issue44310] lru_cache memory leak

Wouter De Borger report at bugs.python.org
Fri Jun 4 07:45:58 EDT 2021


New submission from Wouter De Borger <wouter at inmanta.com>:

# Problem

the functools.lru_cache decorator locks all arguments to the function in memory (inclusing self), causing hard to find memory leaks. 

# Expected  

I had assumed that the lru_cache would keep weak-references and that when an object is garbage colected, all its cache entries expire as unreachable. This is not the case.

# Solutions 

1. I think it is worth at least mentioning this behavior in de documentation. 
2. I also think it would be good if the LRU cache actually uses weak references. 

I will try to make a PR for this.

----------
components: Library (Lib)
messages: 395075
nosy: Wouter De Borger2
priority: normal
severity: normal
status: open
title: lru_cache memory leak
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9

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


More information about the New-bugs-announce mailing list