Skip to content

Strong vs. weak reference

Overview

The observer pattern can cause memory leaks, known as the lapsed listener problem, because in a basic implementation, it requires both explicit registration and explicit deregistration, as in the dispose pattern, because the subject holds strong references to the observers, keeping them alive. This can be prevented if the subject holds weak references to the observers.

References

https://wiki.python.org/moin/EscapingHtml

https://docs.python.org/3/tutorial/introduction.html#using-python-as-a-calculator