Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5279] iOS: Repeatedly Scrolling a Table View Leaks Memory

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2011-10-06T23:41:48.000+0000
Affected Version/sRelease 1.8.0
Fix Version/sSprint 2011-37, Release 1.8.0
ComponentsiOS
Labelsbranch-5062, module_tableview, qe-testadded
ReporterDawson Toth
AssigneeStephen Tramer
Created2011-09-12T16:18:43.000+0000
Updated2014-06-19T12:46:35.000+0000

Description

Problem

When you repeatedly scroll up and down in a table view, memory is progressively leaked and is not reclaimed until a memory warning occurs. Do this for long enough, and the app will crash.

When This Happens

Based on experimentation, I see an inverse correlation between number of rows in the table and how quickly you need to scroll up and down before the table view will start leaking memory. For example, if you only have 50 rows, you have to scroll very quickly to get the problem to start. But if you increase that to 200 rows, it is much easier to see the leak. Further, with 200 rows, if you slowly scroll through, you won't see the problem.

Sample Code

Consider the following code, and download the attached iproducts.png to your resources directory:
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });

var rows = [];
for (var i = 0; i < 200; i++) {
    var row = Ti.UI.createTableViewRow();
    row.add(Ti.UI.createLabel({ text: 'Row ' + i, left: 70 }));
    row.add(Ti.UI.createImageView({ image: 'iproducts.png', left: 10 }));
    rows.push(row);
    row = null;
}
win.add(Ti.UI.createTableView({
    data: rows,
    bottom: 50
}));

var freeMemory = Ti.UI.createLabel({
    height: 50, bottom: 0
});
setInterval(function() {
    freeMemory.text = 'Free Memory: ' + Ti.Platform.availableMemory;
}, 1000);
win.add(freeMemory);

win.open({
    modal: true,
    modalStyle: Ti.UI.iPhone.MODAL_PRESENTATION_FORMSHEET
});

Steps To Reproduce

1. Drop the above in an app.js 2. Download the attached iproducts.png to your Resources directory 3. Run the app on an iPad 1; I have reproduced this in the simulator, but it is easier to see and reproduce on an actual device 4. Slowly scroll through the whole table, making sure all of the rows are loaded. 5. Look at the "Free Memory" label. You probably saw it decrease as the rows were loaded, and then stabilize. Slow scrolling through the table might cause this number to change, but it should stay pretty stable. 6. Now rapidly scroll up and down in the table view. You should be going at a rate of around 2-3 flicks per second to go from top to bottom, and then 2-3 flicks to get back to the top in another second. 7. Keep doing step 6, and watch "Free Memory". It might stay stable for a couple of seconds, but then you should see it go down by a megabyte or more per second. The OS will send a memory warning, and you'll jump back up to having lots of free memory. But it will continue to drain memory, and continue to hit memory warnings, until the OS forces the app to terminate.

Attachments

FileDateSize
iproducts.png2011-09-12T16:18:43.000+00002709

Comments

  1. Reggie Seagraves 2011-09-13

    Probably a duplicate of this.
  2. Stephen Tramer 2011-09-14

    When resolving this bug, please also resolve TIMOB-5247 as DUPLICATE. Confirmed that the fix for this bug works for that one.
  3. Stephen Tramer 2011-10-05

    Issue was reopened and then marked resolved again, due to misidentification.
  4. Alan Vaghti 2011-10-06

    The test in the description of this bug passed as expected with both the iPad simulator 4.3 and the iPad 2 4.3.5 . However the associated bug, TIMOB-5247 continues to fail. There is choppy performance followed by a crash. That test was conducted on an iPod 4.3.3 with SDK 1.8.0.v20111006001414. Reopening issue.
  5. Stephen Tramer 2011-10-06

    By QE's own admission, test passes. Related bug should remain open, and the tag marking this bug as a "duplicate" has been removed because they are clearly separate issues.
  6. Wilson Luu 2011-12-09

    Closing bug. Verified fix on: OS: Mac OS X Lion Titanium Studio, build: 1.0.7.201112080131 SDK build: 1.8.0.1.v20111209102124 Device: iphone 4S (5.0.1)

JSON Source