-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use a weak event handler pattern for GlobalOptionService #68062
Conversation
Done with pass. |
Seems odd to have to change all global option change handlers because we have an issue with one of them. |
We never want GlobalOptionService to be the GC root of an item in the graph. A secondary benefit of this change is GC Root commands in the future will automatically de-prioritize the weak reference from GlobalOptionService and better reveal the true owners of objects in a heap. |
/// } | ||
/// </code> | ||
/// </remarks> | ||
private readonly ConditionalWeakTable<object, EventHandler<TEventArgs>> _keepAliveTable = new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
➡️ It could result in some unexpected semantics if the table overlapped (e.g. removing the event handler from one event might remove the keep-alive status for a different event).
Note that in the current code, only one of these will exist (GlobalOptionService is a singleton).
Force the use of a weak event handler pattern for GlobalOptionService. In the event a PreviewWorkspace fails to be released, it will no longer be GC rooted through this event.
Extracted from #68054