Advanced
Python
Q99 / 101
What is the Python weak reference module and when is it used?
Correct! Well done.
Incorrect.
The correct answer is B) weakref.ref(obj) creates a reference that doesn't prevent GC, useful for caches and observer patterns without memory leaks
B
Correct Answer
weakref.ref(obj) creates a reference that doesn't prevent GC, useful for caches and observer patterns without memory leaks
Explanation
r = weakref.ref(obj); obj = None; r() returns None after GC. weakref.WeakValueDictionary automatically removes entries when values are GC'd.
Progress
99/101