When Is The Best Time to Unsubscribe Events in A Page or A Templated Control? #10906
Unanswered
ShimizuTheLotus
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi community! I'm new to coding with Microsoft.UI.Xaml, and I'm trying to make some apps. I heard that if not unsubscribing a event, it would cause memory leaking.
Microsoft Learn said that I should unsubscribe the events before "before you dispose of a subscriber object", but how can I know when I don't need these events again? I tried unsubscribing in a finalizer, but when the unscribing action was invoked, the debugger will throw an exception telling me the object was already disposed. I did the same in WPF but it won't have that exception. Now I have no idea when to unsubscribe them.
Plus, if there's an anonymous function, how can I unsubscribe it? Or there's no need to unsubscribe them all?
Please help!
Beta Was this translation helpful? Give feedback.
All reactions