Fix: Possible Dispatcher.ShutdownStarted handler memory leak in Tabs#3454
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves cleanup for transient tab views and controls by detaching lifetime event handlers when tabs are closed, reducing the chance of retained controls/view models after tab removal.
Changes:
- Unsubscribes
Dispatcher.ShutdownStartedin multiple tabCloseTab()implementations. - Adds additional
WebConsoleControlcleanup for settings/browser event subscriptions and WebView2 disposal.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
Source/NETworkManager/Views/WhoisView.xaml.cs |
Detaches dispatcher shutdown handler during tab close. |
Source/NETworkManager/Views/TracerouteView.xaml.cs |
Detaches dispatcher shutdown handler during tab close. |
Source/NETworkManager/Views/SNTPLookupView.xaml.cs |
Detaches dispatcher shutdown handler during tab close. |
Source/NETworkManager/Views/SNMPView.xaml.cs |
Detaches dispatcher shutdown handler during tab close. |
Source/NETworkManager/Views/PortScannerView.xaml.cs |
Detaches dispatcher shutdown handler during tab close. |
Source/NETworkManager/Views/IPScannerView.xaml.cs |
Detaches dispatcher shutdown handler during tab close. |
Source/NETworkManager/Views/IPGeolocationView.xaml.cs |
Detaches dispatcher shutdown handler during tab close. |
Source/NETworkManager/Views/DNSLookupView.xaml.cs |
Detaches dispatcher shutdown handler during tab close. |
Source/NETworkManager/Controls/WebConsoleControl.xaml.cs |
Removes settings/browser subscriptions and disposes WebView2 on close. |
Source/NETworkManager/Controls/TigerVNCControl.xaml.cs |
Detaches dispatcher shutdown handler before disconnecting. |
Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs |
Detaches dispatcher shutdown handler before disconnecting. |
Source/NETworkManager/Controls/PuTTYControl.xaml.cs |
Detaches dispatcher shutdown handler before disconnecting. |
Source/NETworkManager/Controls/PowerShellControl.xaml.cs |
Detaches dispatcher shutdown handler before disconnecting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Browser.NavigationStarting -= Browser2_NavigationStarting; | ||
| Browser.NavigationCompleted -= Browser2_NavigationCompleted; | ||
| Browser.SourceChanged -= Browser2_SourceChanged; | ||
| Browser.Dispose(); |
Contributor
There was a problem hiding this comment.
Fixed in 778b736. I added close/cancellation guards in UserControl_Loaded, wrapped the async load path to ignore disposal-related exceptions after close/cancel, and cancel the load before disposing the browser in CloseTab.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this pull request
Related issue(s)
Feedback from Copilot and Claude review
Copilot generated summary
Provide a Copilot generated summary of the changes in this pull request.
Copilot summary
This pull request improves resource management in the application by ensuring that event handlers and subscriptions are properly detached when closing various transient tab controls and views. This change helps prevent memory leaks by allowing these controls and their associated resources to be garbage collected after the tab is closed.
Resource cleanup and event detachment for tab controls:
Dispatcher.ShutdownStartedevent handler in theCloseTab()method for all transient tab controls (PowerShellControl,PuTTYControl,RemoteDesktopControl,TigerVNCControl, andWebConsoleControl) to ensure they can be collected after the tab is closed. [1] [2] [3] [4] [5]WebConsoleControl, additionally removed property change and browser event subscriptions, and disposed of theBrowserinstance to release native resources.Resource cleanup for tab views:
Dispatcher.ShutdownStartedevent handler in theCloseTab()method for all transient tab views (DNSLookupView,IPGeolocationView,IPScannerView,PortScannerView,SNMPView,SNTPLookupView,TracerouteView, andWhoisView) to ensure both the view and its view model can be collected after the tab is closed. [1] [2] [3] [4] [5] [6] [7] [8]To-Do
Contributing
By submitting this pull request, I confirm the following: