Problem Statement
What are weak references and why are they useful?
Explanation
A weak reference lets you refer to an object without increasing its reference count. When the object is reclaimed, the weak reference becomes dead. This avoids memory leaks caused by accidental strong reference cycles.
Use weak references for caches, observer lists, and graphs where you do not own the lifetime. They allow objects to disappear naturally when nothing else needs them.
Code Solution
SolutionRead Only
import weakref class A: pass obj=A() w=weakref.ref(obj) obj=None # target can be collected
