Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1401] iOS: Memory leak on iOS when remove items from section of ListView

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2014-04-23T03:40:36.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsiOS, listview
Reporternicolomonili
AssigneeRitu Agrawal
Created2014-04-16T09:19:09.000+0000
Updated2016-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

FileDateSize
Schermata 2014-04-16 alle 21.44.49.png2014-04-16T19:48:52.000+0000106663
Schermata 2014-04-16 alle 21.45.00.png2014-04-16T19:48:52.000+0000103096

Comments

  1. Ritu Agrawal 2014-04-16

    Please provide a simple runnable test case so that we can reproduce this issue in-house.
  2. nicolomonili 2014-04-16

    description updated with a test code and screenshot
  3. Ritu Agrawal 2014-04-17

    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.

JSON Source