Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7897] Android: Memory leak by windows not properly cleaning up after close.

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2012-07-05T00:21:59.000+0000
Affected Version/sRelease 1.8.2
Fix Version/sRelease 2.0.0, Sprint 2012-06
ComponentsAndroid
Labelsmodule_memory, qe-testadded
ReporterJosh Roesslein
AssigneeJosh Roesslein
Created2012-03-06T13:50:48.000+0000
Updated2012-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

FileDateSize
crashLog.txt2012-03-16T12:08:24.000+00007961

Comments

  1. Josh Roesslein 2012-03-13

    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.
  2. Athanasios Nikolaou 2012-03-16

    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
  3. Wilson Luu 2012-03-16

    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
  4. Josh Roesslein 2012-03-16

    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.
  5. Josh Roesslein 2012-03-16

    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.
  6. Josh Roesslein 2012-03-16

    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".
  7. Marshall Culpepper 2012-03-18

    Resolving since TIMOB-8063 can no longer be reproduced, and test case was updated for emulator use cases
  8. Natalie Huynh 2012-03-19

    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
  9. Shyam Bhadauria 2012-07-05

    Re-opening to edit label.

JSON Source