Skip to content

Fix: Possible Dispatcher.ShutdownStarted handler memory leak in Tabs#3454

Merged
mergify[bot] merged 3 commits into
mainfrom
fix/possible-memory-leak-in-handler
May 29, 2026
Merged

Fix: Possible Dispatcher.ShutdownStarted handler memory leak in Tabs#3454
mergify[bot] merged 3 commits into
mainfrom
fix/possible-memory-leak-in-handler

Conversation

@BornToBeRoot
Copy link
Copy Markdown
Owner

Changes proposed in this pull request

  • Fix possible handler memory leak by unsubscribing

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:

  • Detached the Dispatcher.ShutdownStarted event handler in the CloseTab() method for all transient tab controls (PowerShellControl, PuTTYControl, RemoteDesktopControl, TigerVNCControl, and WebConsoleControl) to ensure they can be collected after the tab is closed. [1] [2] [3] [4] [5]
  • For WebConsoleControl, additionally removed property change and browser event subscriptions, and disposed of the Browser instance to release native resources.

Resource cleanup for tab views:

  • Detached the Dispatcher.ShutdownStarted event handler in the CloseTab() method for all transient tab views (DNSLookupView, IPGeolocationView, IPScannerView, PortScannerView, SNMPView, SNTPLookupView, TracerouteView, and WhoisView) 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:

Copilot AI review requested due to automatic review settings May 29, 2026 23:37
@github-actions github-actions Bot added this to the next-release milestone May 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ShutdownStarted in multiple tab CloseTab() implementations.
  • Adds additional WebConsoleControl cleanup 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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

@mergify mergify Bot merged commit 18f0a10 into main May 29, 2026
5 checks passed
@mergify mergify Bot deleted the fix/possible-memory-leak-in-handler branch May 29, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants