[AC-1401] iOS: Memory leak on iOS when remove items from section of ListView
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2014-04-23T03:40:36.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | iOS, listview |
Reporter | nicolomonili |
Assignee | Ritu Agrawal |
Created | 2014-04-16T09:19:09.000+0000 |
Updated | 2016-03-08T07:37:49.000+0000 |
Description
This Method create a Memory Leak
{quote}
myListView.sections[ id_section ].deleteItemsAt(0,myListView.sections[ id_section ].items.length);
{quote}
I must remove items from a section of ListView, and add some items later with the method (setItems), and I noticed that by Instruments, when call (deleteItemsAt), the objects contained in the item are not unloaded from memory, and then, when recall SetItems , I have a memory leaks problem
TEST CODE
var win = Titanium.UI.createWindow();
var template = {
childTemplates : [{
type : 'Ti.UI.Label',
bindId : 'nome_oggetto',
properties : {
color : 'black',
left : 10
},
}, {
type : 'Ti.UI.Button',
bindId : 'button_piu',
properties : {
width : 30,
height : 30,
right : 10,
title : '+',
visible : false,
font : {
fontSize : 30
},
color : "black",
top : 6,
obj : ""
},
events : {
click : test
}
}],
};
var array_app = [];
for (var i = 0; i < 10; i++) {
array_app.push({
nome_oggetto : {
text : "row " + i,
color : "black"
},
button_piu : {
visible : true
},
properties : {
backgroundColor : "white",
height : 50,
selectionStyle : Ti.UI.iPhone.ListViewCellSelectionStyle.NONE,
font : {
fontSize : 18
}
}
});
}
var listView = Titanium.UI.createListView({
templates : {
'mytemplate' : template
},
defaultItemTemplate : 'mytemplate'
});
var section = Ti.UI.createListSection({
title : "section 1"
});
section.setItems(array_app);
var array_section = [];
array_section.push(section);
listView.sections = array_section;
var delete_btn = Ti.UI.createButton({
title : "remove item",
width : 100,
bottom : 30
});
delete_btn.addEventListener('click', function(e) {
listView.sections[0].deleteItemsAt(0, 1);
});
function test(){
}
win.add(listView);
win.add(delete_btn);
win.open();
Attachments
File | Date | Size |
---|---|---|
Schermata 2014-04-16 alle 21.44.49.png | 2014-04-16T19:48:52.000+0000 | 106663 |
Schermata 2014-04-16 alle 21.45.00.png | 2014-04-16T19:48:52.000+0000 | 103096 |
Please provide a simple runnable test case so that we can reproduce this issue in-house.
description updated with a test code and screenshot
Removing an item from a ListView section marks it ready for garbage collection but it does not mean that the object is collected immediately. Garbage collection timing is based on a number of different factors. A better test would be to add and remove items in a large loop and see if the memory usage continues to go up or stabilizes at some point.