I’m debugging memory leaks in a Django application, and could something curious in django_cachepurge:
from threading import currentThread
_urls_to_purge = {}
def add_purge_url(url):
# ....
_urls_to_purge.setdefault(currentThread(), set()).add(url)
Is such construct prone to memory leaks?
I suspect so, unless I’m not familiar with some Python magic here.
There is no location where the dict is cleaned up.
I don’t know what
currentThreadreturns, but you probably can use the built-inidorhashfunctions on it to get a safe value.If lookup isn’t enough, e.g. because you want to iterate over the container, there is
weakref.WeakKeyDictionary.