Python·100 questions

What is weakref and when is it useful?

Answer
weakref holds a weak reference, not preventing object deletion.
Useful for caches and observers.
When the object is deleted, weakref becomes empty.
There are WeakKeyDictionary/WeakValueDictionary.
Use carefully to avoid unexpected None.
Was this answer helpful?

More questions in this topic

Related questions from other topics