What is the purpose of `weakref.ref()` in Python?

Python Professional Hard

Python Professional — Hard

What is the purpose of `weakref.ref()` in Python?

Key points

  • `weakref.ref()` creates a non-intrusive reference to objects
  • It does not prevent objects from being garbage collected
  • Useful for implementing caches or monitoring objects without impacting memory management

Ready to go further?

Related questions