The PresentationModel classes (e.g. WatchListPresentationModel) in the StockTrader RI collaborate with services to retrieve the data that is shown to the user. Some of these services (e.g. WatchListService) provide events so that the PresentationModel gets
informed when the data changes.
When the PresentationModel adds an event handler to the service event then it couples its lifecycle to the one of the service. Services are often implemented as singletons whereas the View and its associated PresentationModel just lives as long the user edits
the data in the View.
this.watchList = watchListService.RetrieveWatchList();
Because the PresentationModel adds an event handler, the internal event implementation of the service keeps a reference back to the PresentationModel. The garbage collector will never be able to collect the PresentationModel or the View object as long the
service is alive.
1. Use the EventAggregator of the CAL libraries
2. Use the WeakEvent Pattern (see
The first one cannot be used in all scenarios. Thus, I prefer the second solution.
I believe this concept is very important and so I provide a PresentationModel base class that supports this pattern in my project:
Do you have other ideas to solve this memory issue?