Bug 55749 - Webviews aren't being garbage collected when the containing page is popped
Summary: Webviews aren't being garbage collected when the containing page is popped
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.3.4
Hardware: PC Windows
: High major
Target Milestone: ---
Assignee: E.Z. Hart [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-04-28 20:43 UTC by christine.blanda
Modified: 2017-10-05 18:17 UTC (History)
5 users (show)

See Also:
Tags: android performance memory webview ac
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (189.00 KB, application/x-zip-compressed)
2017-04-28 20:46 UTC, christine.blanda
Details
Profiler Results (4.64 MB, application/mlpd)
2017-04-28 20:46 UTC, christine.blanda
Details
Xam support profiler results (2.92 MB, application/x-zip-compressed)
2017-05-01 22:19 UTC, Jimmy [MSFT]
Details

Description christine.blanda 2017-04-28 20:43:00 UTC
In the sample program, ThirdPage contains a webview defined in the xaml.  Nothing is done to the webview in the code.  Run the program and press the ThirdPage button, then the back arrow, 5 times and look at the memory allocations - there are 5 instances of the ThirdPage, WebView, WebViewRenderer, and WebClient (snapshot1 in the attached file).  Not tap the button to garbage collect.  The instances of ThirdPage and WebView drops to one, but WebViewRenderer and WebViewClient are still 5 (snapshot2).  Why aren't these garbage collected?
Comment 1 christine.blanda 2017-04-28 20:46:09 UTC
Created attachment 21894 [details]
Test Project
Comment 2 christine.blanda 2017-04-28 20:46:33 UTC
Created attachment 21895 [details]
Profiler Results
Comment 3 Jimmy [MSFT] 2017-05-01 22:19:57 UTC
Created attachment 21911 [details]
Xam support profiler results

Thank you for filing this report!

I believe I'm seeing the issue when I test with the attached project. I tested with an Android 6.0 device and performed the steps below while taking a snapshot in Profiler after each one. I've attached the results from Profiler, one using 2.3.4 and the other using 2.3.5-pre2.

### Profiling steps

1. Launched the app
2. Press "Open Third Page"
3. Go back
4. Press "Open Third Page"
5. Go back
6. Press "Open Third Page"
7. Go back
8. Press "Garbage Collect"


Each time I navigated to the third page, I could see the number of WebView related object allocations increase and most of the allocations persisted even after the page was popped. After running the GC, the number of allocations for these objects did drop to a single instance as mentioned. 

In contrast, doing the same steps above on iOS results in a similar object allocation while the page is being pushed/popped, but after the GC is ran the objects are completely collected. So this seems to only be affecting Android.

Note You need to log in before you can comment on or make changes to this bug.