[TIMOB-10351] Android: Timers (setTimeout, setInterval) leak memory.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-08-14T16:21:48.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | Sprint 2012-16 API, Release 2.1.2, Release 3.0.0 |
Components | Android |
Labels | core, module_titanium, qe-review, qe-testadded |
Reporter | Josh Roesslein |
Assignee | Josh Roesslein |
Created | 2012-08-08T12:30:54.000+0000 |
Updated | 2012-09-11T09:49:40.000+0000 |
Description
Timers on Android currently never release the callback function
once the timer has finished (fired once or was cancelled). A leak will
be created since the callback function and any objects it retains will never get collected.
Timer leak example
function startTimer() {
// 1 mb buffer
var buffer = Ti.createBuffer({length: 1024 * 1024});
setTimeout(function() {
alert('Buffer: length = ' + buffer.length);
}, 2000);
}
var win = Ti.UI.createWindow();
var startTimerButton = Ti.UI.createButton({title: 'Start timer'});
startTimerButton.addEventListener('click', startTimer);
win.add(startTimerButton);
win.open();
1. Run the test code and monitor the heap usage with DDMS.
2. Click the "Start timer" button and wait for an alert.
3. Dismiss the alert once it is shown and check the heap usage in DDMS.
4. Repeat steps 2-3 and watch for heap growth.
Expected: No long term growth in heap size should happen. It should reach a equilibrium.
Actual: The heap grows indefinitely eventually running out of memory.
Created [PR #2703](https://github.com/appcelerator/titanium_mobile/pull/2703) to resolve issue.
Created [PR #2748](https://github.com/appcelerator/titanium_mobile/pull/2748) to back port fix into 2.1.2 release.
Verified fix with: Titanium Studio, build: 2.1.1.201207271312 Titanium SDK: 2.1.2.v20120815081613 Devices: Droid 2.2.3 Nexus7 4.1 Mac osx 10.8 Mountain Lion