Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added caching of event registration state to support unsubscribes across garbage collections #910

Merged
merged 22 commits into from
Jul 24, 2021

Conversation

manodasanW
Copy link
Member

@manodasanW manodasanW commented Jul 14, 2021

This brings back the fix from #876 that was previously reverted.

In addition to the changes then, there is a couple more changes in this PR some of which are fixes for issues that were discovered related to the fix and others were improvements made to see if it resolves some test failures but were kept even if they didn't as they improved the code:

  • Updated the EventInvoke delegates to be created by the State class to prevent the delegates from keeping the EventSource alive and thereby the WinRT object
  • Made all references to the State object that were cached as weak references. This allows to support the scenario where an object may have events subscribed, but never unsubscribed to not leak when the WinRT object goes away.
  • Removed agile reference support from NativeDelegates as it is now provided by IObjectReference.
  • Made all the event related ConditionalWeakTables lazy initialized as they were a lot of them on the finalizer queue even though they weren't ever used.

Note that the bulk of the event handler fixes can be seen in WinRT.cs

Fixes #842
Fixes #897
Fixes #858

@manodasanW manodasanW merged commit 8e15ac2 into master Jul 24, 2021
@manodasanW manodasanW deleted the manodasanw/fix_event_source_caching_leak2 branch July 24, 2021 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants