[AC-5161] Memory leak in Hello World application
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2017-10-17T19:55:26.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Alloy, Titanium SDK & CLI |
Labels | memoryleak |
Reporter | Yahya Uddin |
Assignee | Shak Hossain |
Created | 2017-08-28T10:05:55.000+0000 |
Updated | 2017-10-17T19:55:26.000+0000 |
Description
I have the following basic Titanium Alloy application:
*index.xml*
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick">Hello, World</Label>
</Window>
</Alloy>
*index.js*
function doClick(e) {
Alloy.createController('foo', {}).getView().open();
}
$.index.open();
*foo.xml*
<Alloy>
<Window>
<View class="container">
<Label id="label">Some text in the foo controller!</Label>
</View>
</Window>
</Alloy>
*foo.js*
$.cleanup = function cleanup() {
$.destroy();
$.off();
$.foo.removeEventListener('close', $.cleanup); // added per @Sharif AbuDarda suggestion
};
$.foo.addEventListener('close', $.cleanup);
I then monitored the amount of memory the Android emulator was using DDMS, based on the instructions provided here: http://docs.appcelerator.com/platform/latest/#!/guide/Managing_Memory_and_Finding_Leaks
When the application started the number of objects was: *32,188*
When I click the button, and then close the new window by pressing back, the number of objects increases to: *32,332*
I do this again, it increases to: *32,478*
Open and close the window about 8 more times, and it increases to: *34,481*
and so on.
The issue is even worse if the window has many objects.
Note I have tested this on both an Android Emulator (Nexus 4) and a real Android device (Samsung S6).
This issues seems to occur on *6.1.X GA*
NOTE: I have not yet tested this on iOS yet.
Hello, The evidence you showed showing a little memory increase. This much is usually negligible. Also, remove any event in the window before closing window. Thanks.
Note that removing the event listener did not seem to fix the issue