Unsubscribe from events with strong reference when application ends?

Topics: Prism v2 - WPF 3.5
Jun 18, 2009 at 9:13 AM


I am writing a modular application using Prism. My events were not always being received; apparently parts of the application were getting garbage collected. I solved this by using strong references when subscribing to events.

On to my question: In the documentation, you state that if I subscribe using a strong reference, I should also unsubscribe. Should this also be done when the application ends (so I should write a Dispose/Finalizer pattern)? Currently all my modules persist until application end.

Kind regards,

Daniel Rose

Jun 19, 2009 at 6:27 PM

Hi Daniel,


The EventAggregator Quickstart solution (that comes with the Prism guidance), provides an example of how to unsubscribe from Event Aggregator events.

You can check the ~DecompressionFolder\Quickstarts\EventAggregation\Event_Aggregation.Desktop.sln solution. In the ActivityPresenter class, from ModuleB project you will find this example.


When the application ends the process ends and therefore all the memory is released, so it should not be necessary to unsubscribe from events in that case. One only warning is that for the application to end all windows should be closed. We have seen some cases where for some reason the application had non-visible windows. Those windows should also be closed for the application to end correctly (you can check if the process disappears from the task manager).


Please let me know if this helps.


Damian Schenkelman