![]() ![]() This may cause a crash depending on the data structure used by the subject to store the observers. The problem is that while a subject is notifying one of the observers, an observer decides to attach or detach to/from the subject. Observer attaches or detaches during a notification For example, Z may see a value of Y that should be impossible given the value of X. Then Z may access a dirty cached value in Y, because Y hasn't yet been marked as dirty by X.Ī dirty read can be a source of surprises. Let X be changed and X notifies Z before Y. This typically leads to a redundant edge in the dependency graph: However in practice it is common for objects to host multiple caches, so that there may be cycles at the coarse resolution of objects. Now technically cycles should be impossible, and that is indeed the case if data dependency is represented at a fine-grained enough level. This occurs when there is a cycle in the dependency graph. The leak happens when an observer fails to unsubscribe from the subject when it no longer needs to listen.Ĭonsequently, the subject 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 subject is alive, which could be until the end of the application. Observer pattern registration#In basic implementation, this requires both explicit registration and explicit deregistration, as in the dispose pattern, because the subject holds strong references to the observers, keeping them alive. Memory leaks caused by Lapsed listener problem because of explicit register and unregistering of observers.It originates in the observer pattern, where observers (or listeners) register with a subject (or publisher) to receive events.What are the Disadvantages of Observer pattern? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |