[TIMOB-13250] Android: Memory leak in Ti.UI.WebView
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2013-05-03T22:44:19.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2013 Sprint 09 Core, 2013 Sprint 09 |
Components | Android |
Labels | exalture, triage |
Reporter | Carter Lathrop |
Assignee | Allen Yeung |
Created | 2013-03-06T14:48:33.000+0000 |
Updated | 2017-03-21T22:15:26.000+0000 |
Description
When closing a webview, memory is not released properly. Removing the webview and nulling variables does not solve the problem.
App.js:
(function() {
var w = Ti.UI.createWindow();
w.exitOnClose = true;
w.setBackgroundColor("red");
w.setNavBarHidden(true);
var b = Ti.UI.createButton();
b.setTitle("Press me");
b.addEventListener('click', function()
{
var w2 = Ti.UI.createWindow();
w2.setModal(true);
w2.setNavBarHidden(true);
w2.setBackgroundColor("white");
var l = Titanium.UI.createWebView({
html:'hello world'
});
w2.add(l);
w2.addEventListener('android:back', function(e){
w2.remove(l);
l = null;
w2.close();
w2 = null;
});
w2.open();
});
w.add(b);
w.open();
})();
Steps to reproduce:
1) Launch app and check memory used (aprox 16mb)
2) Click the button to open the new window with the webview
3) Close the window with back button and check memory used (22mb)
4) Repeat steps 1-3. Every time window with webview is opened and closed,
memory used is increased by aprox 1mb.
Adding another example that demonstrates the memory leak. Now adding the webview directly to the main window:
Tested in 2.0.2.GA, 3.0.0.GA and 3.1.0
We need to call webView.release() while closing the window to release the memory related to webview in Android. http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.WebView-method-release But in the example, we are not calling this API. Don't we need to call this API?
Calling webView.release() helps in general. However TiWebViewBindings are still leaking. But everything is being released when related Activity is destroyed.
I've tried both test cases multiple times and I can't reproduce the memory leak here. Occasionally I see the memory build up a little when going back and forth, but it eventually goes back down. I opened over 10 webviews, and when I look at the heap dump, I see 0-3 instances of the webview being retained. Keep in mind that this number will vary depending on GC lag. There's no guarantee that the webviews will be cleaned up as soon as you hit the gc button in ddms. Going to mark this as cannot reproduce. Feel free to reopen if there is further information that can help reproduce this issue.
Closing ticket as the issue cannot be reproduced and due to the above comments.