Skip to content

Release Help/Release Notes WebView when leaving the page - #5131

Merged
Gabriel Dufresne (GabrielDuf) merged 1 commit into
mainfrom
fix/5129-webview-lifecycle
Jul 17, 2026
Merged

Gabriel Dufresne (GabrielDuf) merged 1 commit into
mainfrom
fix/5129-webview-lifecycle

Conversation

@GabrielDuf

Copy link
Copy Markdown
Contributor

This pull request improves resource management for pages hosting WebView2 controls by ensuring that the associated processes are properly released when navigating away from the Help or Release Notes pages. This change prevents unnecessary resource usage and potential memory leaks by disposing of these pages and their WebView2 instances when they are no longer in use.

Resource management improvements for WebView2 pages:

  • Added the IDisposable interface and a Dispose method to both HelpPage and ReleaseNotesPage, which stops the WebView2 control and detaches it from the UI when the page is disposed.
  • Introduced the ReleaseWebViewPage method in MainWindowViewModel to dispose of and release cached instances of HelpPage and ReleaseNotesPage when navigating away from them, ensuring their WebView2 process clusters are freed.
  • Updated the navigation logic in MainWindowViewModel.NavigateTo to call ReleaseWebViewPage when switching pages, further ensuring proper cleanup of WebView2 resources.

@GabrielDuf
Gabriel Dufresne (GabrielDuf) merged commit accf456 into main Jul 17, 2026
5 checks passed
@GabrielDuf
Gabriel Dufresne (GabrielDuf) deleted the fix/5129-webview-lifecycle branch July 17, 2026 18:06
@GabrielDuf Gabriel Dufresne (GabrielDuf) linked an issue Jul 17, 2026 that may be closed by this pull request
4 tasks done
Mathew Newman (Thenewmanator15) added a commit to Thenewmanator15/UniGetUI that referenced this pull request Nov 16, 2026
Leaving the Help or Release Notes page disposes the page and detaches its
web view (Devolutions#5131), and hiding the window to the tray now does the same.
With Avalonia.Controls.WebView 12.0.0 that had no effect on Windows: the
control never destroyed its WebView2 adapter (AdapterDestroyed was never
raised), so the msedgewebview2 process cluster stayed alive and every
return to the page added another renderer process.

Measured on Windows by opening Help and then navigating to Discover:

  12.0.0 / 12.0.1: 6 msedgewebview2 processes still running 23 s after
                   leaving; 7 after opening Help again.
  12.1.2:          0 processes 3 s after leaving; 6 after opening Help
                   again.

The adapter is internal to the package, so it cannot be disposed from
our side without reflection. The rest of Avalonia stays on 12.0.4; the
solution builds and the test suite gives the same result as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Mathew Newman (Thenewmanator15) added a commit to Thenewmanator15/UniGetUI that referenced this pull request Nov 16, 2026
Leaving the Help or Release Notes page disposes the page and detaches its
web view (Devolutions#5131), and hiding the window to the tray now does the same.
With Avalonia.Controls.WebView 12.0.0 that had no effect on Windows: the
control never destroyed its WebView2 adapter (AdapterDestroyed was never
raised), so the msedgewebview2 process cluster stayed alive and every
return to the page added another renderer process.

Measured on Windows by opening Help and then navigating to Discover:

  12.0.0 / 12.0.1: 6 msedgewebview2 processes still running 23 s after
                   leaving; 7 after opening Help again.
  12.1.2:          0 processes 3 s after leaving; 6 after opening Help
                   again.

The adapter is internal to the package, so it cannot be disposed from
our side without reflection. The rest of Avalonia stays on 12.0.4; the
solution builds and the test suite gives the same result as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Unclosable Built-in Web Browser leading to RAM hogging

2 participants