In java observer pattern , Subject has a List of observers which is populated once observer register's on Subject.
Suppose 1000 observers have register on Subject. Subject is having a List in Subject Class.
Now after few days, observer is no longer interested in notification from subject but observer forget to ( or he is lazy ) do unregister.
Now here Subject contains unnecessary observer's object in the List which is wasting memory unnecessary.
What is the solution if memory is really important and don't want to waste memory.
Is the solution lie's in weak references ?
Or while doing register, we do register for lets say 10 days and after that observer has to re-register.
Aucun commentaire:
Enregistrer un commentaire