In the Observer pattern, what is the best way to prevent memory leaks when the Subject maintains a list of Observers?
weakref.ref allows the Subject to notify observers without preventing their garbage collection.
Why this answer
If the Subject maintains strong references to Observers, they cannot be garbage collected. Using weak references allows them to be collected when no longer used elsewhere.