World Library  
Flag as Inappropriate
Email this Article

Lapsed listener problem

Article Id: WHEBN0036899126
Reproduction Date:

Title: Lapsed listener problem  
Author: World Heritage Encyclopedia
Language: English
Subject: Weak reference, Software anomalies, Software bugs
Collection: Articles with Example Pseudocode, Software Anomalies, Software Bugs
Publisher: World Heritage Encyclopedia
Publication
Date:
 

Lapsed listener problem

The lapsed listener problem is a common source of memory leaks for object-oriented languages, among the most common ones for garbage collected languages.[1][2]

It originates in the observer pattern, where observers (or listeners) are registering with a subject (or publisher) to receive events. In basic implementation, this requires both explicit registration and explicit deregistration, as in the dispose pattern, because the publisher holds strong references to the observers, keeping them alive. The leak happens when a listener forgets to unsubscribe from the publisher when it does not need to listen anymore. Consequently, the publisher still holds a reference to the observer which prevents it from being garbage collected — including all other objects it is referring to — for as long as the publisher is alive, which could be until the end of the application.

This causes not only a memory leak, but also a performance degradation with an "uninterested" observer receiving and acting on unwanted events. This can be prevented by the subject holding weak references to the observers, allowing them to be garbage collected as normal without needing to be unregistered.

References

  1. ^ What is the lapsed listener problem?, Andy McMullan
  2. ^ Memory Loiterers in Java, Ethan Henry and Ed Lycklama
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.