[TIMOB-7897] Android: Memory leak by windows not properly cleaning up after close.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-07-05T00:21:59.000+0000 |
Affected Version/s | Release 1.8.2 |
Fix Version/s | Release 2.0.0, Sprint 2012-06 |
Components | Android |
Labels | module_memory, qe-testadded |
Reporter | Josh Roesslein |
Assignee | Josh Roesslein |
Created | 2012-03-06T13:50:48.000+0000 |
Updated | 2012-07-05T13:59:35.000+0000 |
Description
Windows appear to be leaking memory by not properly cleaning up
after they have been closed. This only affects "heavy" windows that have their own activity.
Test Case: Opening a window and adding many child views.
Run the application and click the button to open a window. Wait for an alert dialog to popup telling you its okay to back out now. Hit the back button to close out the window. Repeat this process. Expected: Memory usage should peak and remain steady. Actual: Memory usages constantly rises until out of memory crash occurs.
function mainViews() {
var newWin = Ti.UI.createWindow({ navBarHidden: true });
Ti.API.info('****** mainViews function has started ******');
var views =[];
var view = null;
for (var i=0; i < 500; i++) {
view = Ti.UI.createView();
views.push(view);
newWin.add(view);
}
newWin.open();
alert("You may click back now.");
Ti.API.info('Titanium views created and added to array');
Ti.API.info('****** mainViews function has stopped ******');
}
var win = Ti.UI.createWindow({
backgroundColor: "white"
});
var button = Ti.UI.createButton({
title: "create 5k views"
});
button.addEventListener("click", function(e) {
mainViews();
Ti.API.info('Available memory: ' + Ti.Platform.availableMemory);
});
win.add(button);
win.open();
Attachments
File | Date | Size |
---|---|---|
crashLog.txt | 2012-03-16T12:08:24.000+0000 | 7961 |
Sent [Pull Request #1662](https://github.com/appcelerator/titanium_mobile/pull/1662) to resolve issue. This works around a bug in older Android versions which appear to "leak" Messenger that are passed within an Intent's extra. To reduce the affects of this leak, moved Handler callback implementation into a static, nested class. This allows the "expensive" TiUIActivityWindow to get collected and reduces memory leak to a very minimal level.
Hi, I am a little bit confused... Is this ticket really resolved? The above provided test case crashes on emulator after 2 clicks (i used continuous builds - version 2.0.0.v20120315091738). Thank you in advance, Athanasios Nikolaou
Reopening bug. Was able to reproduce bug on: SDK build: 2.0.0.v20120316104738 Runtime: v8 Titanium Studio, build: 2.0.0.201203152033 Device: Emulator Google API 2.2 See crashLog.txt Note: * No memory crash when running on Emulator Google API 2.2, rhino * No memory crash when running on device Nexus S (2.3.6), v8 and rhino
This test case is probably too extreme for emulator (it has a global reference limit of only 2000). If you lower the number of views to something less intense (say 500) it might perform better. Looking at the crash log looks like you had 1000 Phantom references. These are objects that are marked, but not yet swept away by the GC.
Going to review this closer and determine if the phantom references are caused by a bug in our platform or just due to Dalvik's GC.
Update test case to only create 500 views each time. Also added an alert to notify you once all views have been added to the window. If you try backing out of the activity for the new window will it is opening, we get into a bad state. I'll rise a separate issue to review this behavior and how we should address it. After lowering the view count to 500 and only backing out of the window after I get the "alert" I see the gref count on emulator staying steady and bellow the "limit".
Resolving since TIMOB-8063 can no longer be reproduced, and test case was updated for emulator use cases
Tested with Emulator 2.2. Clicked on create 5k view 10 times and did not get a crash. Tested with 2.0.0.v20120319003254 and studio: 2.0.0.201203182248
Re-opening to edit label.