the tiltle says it all, in my window (not the main window) constructor i have
EventAggregator.OnUserLoggedIn += OnUserLoggedIn;
EventAggregator.OnUserLoggedOff += OnUserLoggedOff;
is there a difference between
this.Close()
and
EventAggregator.OnUserLoggedIn -= OnUserLoggedIn;
EventAggregator.OnUserLoggedOff -= OnUserLoggedOff;
this.Close()
i've read that closing the window disposes all unmanged resources, are those events considered maneged or unmanaged?
Those events are managed resources if anything (I'm not sure if you can call events resources though).
Yes, you should unhook event handlers from child windows (not main window as it doesn't matter) otherwise you may experience memory leaks as garbage collector won't be able to pick up those objects as still having references.
Check this blog for more info on memory leaks and event handlers:
A classic leak common to all .NET applications, and a common oversight by developers. If you create an event handler to handle events occurring in some other object then, if you don't clear the link when you've finished, an unwanted strong reference will be left behind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With