I've got a UserControl. (call this the Parent UC)
The Parent UC loads another UserControl (Call this the Child UC)
The Child UC subscribes to an event that is happening in the Parent UC.
No probllem so far all of that is working just fine.
But thinking about it - my understanding is that when the Child UC is unloaded it won't be garbage collected because the event in the parent UC still has a reference to the event handler in the child UC.
So, I want the Child UC to unsubscribe to the event before unloading.
But the Child UC doesn't have any UnLoad event so doesn't actually know when it's being unloaded. Should I just unsubscribe in the child uc's dispose method ?
Although while typing all that I've just remembered that I never actually unload the Child UC. It's the Parent UC that is unloaded by 'its' parent (The WIndows Form) so I don't need to worry about memory leaks (do I ?)
But, just because i typed all that, where 'would' the child uc unsubscribe to the event in the parent uc if I did for some reason want to unload the Child UC while keeping the parent UC ?
If you see what I mean. er. I think.![]()


Reply With Quote
