Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2188] iOS: Severe memory leaks produced when appending/deleting/inserting rows to the table

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2013-12-04T22:43:32.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsappendRow, deleteRow, insertRowBefore, tableView, tableViewRow
ReporterLee phela
AssigneeSabil Rahim
Created2013-12-03T18:22:09.000+0000
Updated2016-03-08T07:41:10.000+0000

Description

Step 1. Open iOS instruments and set the filter to tiui Step 2. Put the code below into app.js and run it
function crTable(){
	var t=Ti.UI.createTableView({
			editable:true,
			className:'testing'
		});
		
		var tdata=[];
		for(var k=0;k<100;k++){
			tdata.push(Ti.UI.createTableViewRow({
				title:'hello'+k
			}));
		}
		t.setData(tdata);
		return t;
}

function tableWindow(){
	var win=Ti.UI.createWindow({
		backgroundColor:'#fff'
	});
	
	
	var table=crTable();
	win.add(table);
	
	
	//window close button
	var closeButton=Ti.UI.createButton({
		title:'Close window',
		top:10,
		zIndex:1
	});
	
	closeButton.addEventListener('click',function(){
		win.close();
		
	});
	win.add(closeButton);
	
	
	//rows append button
	
	var appendButton=Ti.UI.createButton({
			title:'Append table rows',
			top:50,
			zIndex:1
	});
	
	appendButton.addEventListener('click',function(){
		var rows=[];
		for(var k=0;k<10;k++){
			rows.push(Ti.UI.createTableViewRow({
				title:'row appended'+k
			}));
		}
		table.appendRow(rows);
	});
	
	win.add(appendButton);
	win.open();
}


var mainWin=Ti.UI.createWindow({
	backgroundColor:'#fff'
});
var openTableButton=Ti.UI.createButton({
	title:'Open new window with table'
});
openTableButton.addEventListener('click',tableWindow);
mainWin.add(openTableButton);
mainWin.open();
Step 3. Click the button 'open new window with table' Step 4. Click the button 'Append new row' or alternatively , swipe a table row to the left and delete it Step 5. Click the button 'Close button'. Step 6. Repeat from steps 3 to 5 several times. Description: The methods of the table such as ** table.appendRow(row) ** table.deleteRow(row) ** table.insertRowBefore(index,row), etc when used to alter an already existing table, produces severe case of memory leaks. The behaviour of the leaks is described below very precisely - *1.* Open the window containing the table. The table has about 100 rows in it. *2.* Click the button 'Append table rows'. *3.* After appending, close the window and watch the changes in the instruments . *4.* Repeat these steps until you can see only *TiUITableViewRowProxy* and *TiUITableViewCell* retained alone in the instruments with 13kb+ memory allocated to the former and about 5kb+ memory allocated to the later. Do not click again the append button or delete any rows until you get to see the expected result in the instruments so as to give a better view of the nature of leaks. *5.* As soon as you obtained the expected result, start it over again from the first step for the second time but this time, by clicking the append row button too. *6.* Close the window and inspect the memory in the instruments. *7.* Now the *TiUiTableViewRowProxy* goes up to about 26kb+ and *TiUITableViewCell* to about 10kb+ *8.* As you keep on repeating these steps, each time the window is opened and close, the *TiUITableViewRowProxy* and *TiUITableViewCell* memory allocation gets incremented every time by about 13kb+ and 5kb+ respectively and never gets cleared at all. _However, if you simply open and close the window( i,e if you don't append or delete any rows), every TiUI proxy gets cleared on windows closed( this does not mean that the memory leak that was induced earlier by the append/delete methods gets cleared too but they remain stuck forever and increases as you opens and close the window after appending/deleting/altering the table) ._

Comments

  1. Sabil Rahim 2013-12-04

    I tried the same code on simulator and the views do stay around even after you close the window containing the tableview. But once you do "Simulate Memory Warning" all the closed tableviewRows (and the associated ui elements) are being removed properly. On device, this is hard to verify as we can not ascertain when the garbage collector might kick in and hence it might seem like the views are still staying around but they are actually released and waiting around for the next GC cycle to completely remove it. marking ticket as invalid. Tested with cli 3.2.0-beta, SDK 3.2.0.v20131203104847
  2. Lee phela 2013-12-04

    Thank you for looking at it. As per your testing environment, I just upgraded to SDK 3.2.0 and run my own test here but the leakage is still there. Like you said, I have even done the *Simulate memory warning* but to no effect and the *TiUITableViewRowProxy* and *TiUITableViewCell* still hangs on. Im *100%* sure that you've never click the *Append table rows* button to append rows to the existing table but just close down the window at the first sight on opening. I have made very clear from my post that under such a scenerio, no leakage is produced but only when the table is altered by means of appending/deleting/inserting, only then the leak is produced. Please re-open this issue. Thank you
  3. Sabil Rahim 2013-12-05

    [~spaceman12] I did my original testing as per the instructions on the ticket. I did double check it on 6.1 and 7.1 simulator and found the same result. Please [check the video](https://www.dropbox.com/s/dd7mn2oyoqks62i/ios7.1.mov) attached for what i was doing during testing Video https://www.dropbox.com/s/dd7mn2oyoqks62i/ios7.1.mov Please do let me know if i have missed any steps. Thanks
  4. Lee phela 2013-12-05

    Updated the *xcode* to the latest version and the leak is gone now. Thank you for your time.
  5. Shak Hossain 2013-12-27

    Closing as per updates fro Lee.

JSON Source