I'm building a hybrid android app that opens up a webview and inside of it creating and removing iframes.
As part of memory optimizations, I isolated only the creation and removal of the iframe and found out that iframe is not released in the webview, while in the browser it works well.
I did the Following test twice. First, on Chrome browser (Chrome v39). Second, on Google Nexus 4 (KitKat 4.4).
The test:
- Run the html as written in jsbin: http://jsbin.com/yubuvokawa/1/
- Start recording timeline in devtools.
- Click Create.
- Click Remove.
- Garbage collection.
- Stop Recording.
These are the results as shown in the Chrome browser:
Iframe is created and destroyed and goes back to normal (except additional JS heap)
These are the results as shown in the Nexus 4 webview:
As you can see, when the iframe is released, the document is still alive (the red line) as well as some unreleased nodes
This is the piece of code I'm using to open a webview:
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
String url = getIntent().getExtras().getString("url");
Log.w(getClass().getSimpleName(), "Loading url: " + url);
webView.loadUrl(url);
What can cause the difference? how should I clean the iframe from the webview?