I've read through a lot of webpages discussing how to control memory leakage in a Titanium-based mobile application for Android.
My situation is that I'm building an app that uses multiple levels of lists (in practice these are tableViews) where the user can navigate through. It is using one window, and when the user selects a list item a new view is created which is animated right-to-left. I have chosen this option, as it appeared to be impossible to create a new window which slides in from right to left an all platforms.
In every view, an eventListener is created to check which tableRow is clicked, and the corresponding submenu is then created and is animated into the screen.
I notice that the memory usage is steadily growing after each click on a view, but I'm can't seem to pinpoint where the memory leak is present.
Currently I'm checking the main window to see if the window has been animated out of view (then the .left property is 320 on a 320px wide device). Then I remove this view from the window, and set the proxy to null, using:
for ( i = 0; i < win.children.length; i++) {
if ( (win.children[i] != null) && (win.children[i].left == 320) ) {
win.remove(win.children[i]);
win.children[i] = null;
}
}
It is still building up memory usage though. This could be because every new view contains a table and an event listener, using a function containing:
var sub_table = Ti.UI.createTableView({top:'50dp',separatorColor: rowSeparatorColor});
sub_table.setData(data);
sub_table.addEventListener('click', function(e) {
create(e.rowData.data);
});
new_view.add(my_navbar);
new_view.add(sub_table);
return new_view;
Do I have to erase them separately or are they destroyed when the view is destroyed? Of I have to erase them manually, how would I go about that?
On a more general note, I don't know how to determine the causes of memory usage. Is there a way to get all objects and/or variables that are in memory at a certain time? Is there a way to drill down on the memory usage that the Dalvik toolkit provides? Is there a method for obtaining all global variables or event listeners?
removeEventListener
– Josiah Hester