Skip to content
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

Right way to dispose page with WebView #18021

Open
ac-lap opened this issue Oct 14, 2023 · 10 comments
Open

Right way to dispose page with WebView #18021

ac-lap opened this issue Oct 14, 2023 · 10 comments
Labels
area-controls-webview WebView platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@ac-lap
Copy link

ac-lap commented Oct 14, 2023

Description

Android app has 2 pages, 1 home page and 1 page containing WebView. From home page user can go to the WebView page and open a site, come back to the home page and again go to WebView page to open other site, user can do this multiple times.

After few such cycles, in edge://inspect/#devices you see multiple instances of the WebView and with page navigating away the WebView is not going away, I am concerned that this is causing memory leak.

image

I see the WebView class does not has any close/dispose/destroy kind of methods. What is the proper way to close the page containing WebView so that all resources are properly released?

I have attached the sample app which reproduces the issue. Pasting some code snippets for quick reference -

        private async void OnCounterClicked(object sender, EventArgs e)
        {
            List<string> siteList = new List<string>() { "https://www.google.com", "https://www.bing.com", "https://www.youtube.com", "https://www.microsoft.com" };
            Random rnd = new Random();
            await Navigation.PushAsync(new NewPage1(siteList[rnd.Next(0, siteList.Count)]));
        }
    public NewPage1(string site)
    {
        InitializeComponent();
        webview.Source = site;
    }
    private void GoBack(object sender, EventArgs e)
    {
        Navigation.PopAsync();
    }

Steps to Reproduce

  1. Build and start the app attached in the zip on Android device.
  2. Click on 'Click me'
  3. New page with site loads, click 'Go Back'
  4. Repeat step 2 and 3 few times.
  5. Open edge://inspect/#devices
  6. Look for the device, you'll see all instances of WebView

MauiAppWebView.zip

Link to public reproduction project repository

No response

Version with bug

7.0.96

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@ac-lap ac-lap added the t/bug Something isn't working label Oct 14, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Oct 16, 2023
@ac-lap
Copy link
Author

ac-lap commented Oct 22, 2023

Folks, any guidance around this? It's kind of a fundamental issue.

@jsuarezruiz @jfversluis

@Denny966
Copy link

Bump

@ac-lap
Copy link
Author

ac-lap commented Jan 10, 2024

Folks any help on this issue?

@MartyIX
Copy link
Contributor

MartyIX commented Jan 25, 2024

In .NET 8, there is #18810. Maybe that would need to be backported?

@AdamEssenmacher
Copy link

AutoDisconnectBehavior from my memory toolkit might help here: https://github.com/AdamEssenmacher/MemoryToolkit.Maui

I haven't tested it out on WebViews yet, but since you're not getting much help here it might be worth a try.

@RoiChen001
Copy link

Can't repro this issue on Android device on the latest 17.10.0 Preview 3(8.0.0-preview.1.7762).

@RoiChen001 RoiChen001 added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Apr 17, 2024
@adamdzk
Copy link

adamdzk commented Apr 18, 2024

Can't repro this issue on Android device on the latest 17.10.0 Preview 3(8.0.0-preview.1.7762).

As from what I can see 8.0.0-preview.1.7762 is from 2/21/2023. Is it the version you have in mind?

@ac-lap
Copy link
Author

ac-lap commented Apr 19, 2024

The issue still reproduces for me on net 8 and physical android device.

image
image

I have re-uploaded the repro project with net 8.

MauiAppWebView_net8.zip

This is quite serious issue, and would appreciate any assistance on this.

@RoiChen001 plz remove the try-latest-version label.

@dotnet-policy-service dotnet-policy-service bot removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Apr 19, 2024
@RoiChen001
Copy link

Can repro this issue at Android platform on the latest 17.10 Preview 6(8.0.20&8.0.21).
18021

@RoiChen001 RoiChen001 added the s/verified Verified / Reproducible Issue ready for Engineering Triage label May 7, 2024
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 6, 2024
@BobbyOrtizXogo
Copy link

I have the same issue. How can this not be a HIGH priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-webview WebView platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants