Skip to content

Archive

Weakref

1 articles
Python 02 Sep 2026 8 min read

Weak References in Python: Caches, Object Lifetimes, and Cleanup

A normal Python reference keeps an object alive. That is usually exactly what you want: if a dictionary contains an object, the object should remain available while the dictionary needs it. Some infrastructure has a different requirement. A cache, registry, or metadata table may want to refer to an object without becoming the reason that object stays alive forever. Python’s weakref module provides references and containers for that ownership model.