1

I am using Loaded/Unloaded event of the XAML view.

Constructor()
{
   InitializeComponent()
   Loaded += LoadedEvent;
   Unloaded += UnloadedEvent;
}

Is it required to unhook these events like Loaded -= LoadedEvent?? or it wont impact in the garbage collection of the View?

Learner
  • 1,490
  • 2
  • 22
  • 35

1 Answers1

3

In case View is getting destroyed, you need not to worry about unhooking these event handlers. Garbage collection will take care of this.

For event handling, memory leak occurs in case Publisher life time is more than it's subscriber (Publisher holds on to the subscriber instance via Invocation list).

But, in your case publisher and subscriber are same. So, you don't have to worry for unhooking these event handlers.

You can read more about it here - Why and How to avoid Event Handler memory leaks ?

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185