Closing NativeWebDialog or NativeWebView does not terminate their processes, causing memory not to be released.
I couldn't find the correct method in the documentation for properly closing a WebView process and releasing its memory.
Ideally, each time a WebView window is closed, its associated WebView renderer process should be terminated. When all WebView windows are closed, the WebView manager process and the WebView GPU process should also be terminated.
Here is a simple reproduction code: open multiple windows containing a NativeWebView control, or open multiple NativeWebDialog instances, and then close them all.
// MainWindow.axaml
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Width="500" Height="100" Position="10 10"
x:Class="AvaloniaApplication1.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="AvaloniaApplication1">
<StackPanel Orientation="Horizontal">
<Button Margin="8" Click="OpenNativeWebViewWindow">Open NativeWebView Window</Button>
<Button Margin="8" Click="OpenNativeWebDialog">Open NativeWebDialog</Button>
</StackPanel>
</Window>
// MainWindow.axaml.cs
using System;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace AvaloniaApplication1.Views;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OpenNativeWebViewWindow(object? sender, RoutedEventArgs e)
{
new WebViewWindow().Show();
}
private void OpenNativeWebDialog(object? sender, RoutedEventArgs e)
{
var dialog = new NativeWebDialog { Title = "Preview", Source = new Uri("https://docs.avaloniaui.net/") };
dialog.Show();
}
}
// WebViewWindow.axaml
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Width="800" Height="500"
x:Class="AvaloniaApplication1.Views.WebViewWindow"
Title="WebViewWindow">
<Border BorderBrush="#BBB"
BorderThickness="1"
Padding="0"
Margin="8">
<NativeWebView x:Name="WebView"
Source="https://docs.avaloniaui.net/"
Focusable="False" />
</Border>
</Window>
using System;
using Avalonia.Controls;
using Avalonia.VisualTree;
namespace AvaloniaApplication1.Views;
public partial class WebViewWindow : Window
{
public WebViewWindow()
{
InitializeComponent();
}
}
Closing NativeWebDialog or NativeWebView does not terminate their processes, causing memory not to be released.
I couldn't find the correct method in the documentation for properly closing a WebView process and releasing its memory.
Ideally, each time a WebView window is closed, its associated WebView renderer process should be terminated. When all WebView windows are closed, the WebView manager process and the WebView GPU process should also be terminated.
Here is a simple reproduction code: open multiple windows containing a NativeWebView control, or open multiple NativeWebDialog instances, and then close them all.