[TIMOB-3166] significant memory leak with thumbnails in tableview
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-05-11T17:13:03.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.7.0, Sprint 2011-11 |
Components | iOS |
Labels | ios, klist, memory |
Reporter | Brian |
Assignee | Reggie Seagraves |
Created | 2011-04-15T03:38:32.000+0000 |
Updated | 2011-05-11T17:13:03.000+0000 |
Description
We are using Titanium 1.6RC1 with Developer 1.2.2 and think we have found a significant memory leak when displaying remote thumbnails in a tableview. Below is the code to reproduce.
Upon running the code, just attach to the process using XCode Instruments. Then click the "Photos" button to bring up the grid of photos, then click back to close the window. Continue to do this over and over again and you will see the living memory allocations continue to increase to extremely high levels.
Why doesn't closing a window free up all it's memory usage? I come from the Objective-C world and have created this same screen natively with no memory leaks. Am I missing something in our javascript code? This is a showstopper for us if we cannot find a solution.
Thanks!
Brian
var tabGroup = Titanium.UI.createTabGroup({id:'tabGroup1'});
win = Titanium.UI.createWindow({id:'win1',backgroundColor:'#fff'});
var button = Ti.UI.createButton({title:'Photos',width:100, height:100});
button.addEventListener('click', function() {
var photosWindow = Titanium.UI.createWindow({fullscreen:false});
var tableView = Ti.UI.createTableView({
separatorStyle:Ti.UI.iPhone.TableViewSeparatorStyle.NONE
});
photosWindow.add(tableView);
tab1.open(photosWindow, {animated:true});
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
var list = JSON.parse(this.responseText).List;
var rowData = [];
for (var i = 0,count = list.length; i < count; i += 4) {
var row = Ti.UI.createTableViewRow({
height:'auto',
selectedBackgroundColor: '#fff',
backgroundSelectedColor: '#fff',
className:'tvRow'
}),imgDimensions = 80;
var offSet = 0;
for (var j = 0; j < 4; j++) {
var photo = list[i + j];
if (photo) {
var photoView = Ti.UI.createImageView({
top:0,
left:offSet,
height:imgDimensions,
width:imgDimensions,
image:photo.ThumbnailUrl
});
row.add(photoView);
offSet += imgDimensions;
}
}
rowData.push(row);
}
tableView.setData(rowData);
};
var url = "http://idancemobile.com/event/e2e530/api/2.0/images/0";
xhr.open("GET", url);
xhr.send();
});
win.add(button);
var tab1 = Titanium.UI.createTab({
id:'tab1',
window:win
});
tabGroup.addTab(tab1);
tabGroup.open();
Memory management is a priority for 1.7.0. Examples like this help a great deal, especially since they include some information about the original data being used.
I created another example that better displays the image memory issue in the tableview. When running the code below just keep hitting "Refresh" and you will see the "available memory" as the title. Eventually it gets so low that it crashes.
Sorry for so many code posts :) But I think I have the perfect example of what is going wrong....please use the following instead of the previous two :) If you click the "Launch" button and then click the back button over and over again you will see the "available memory" continue to lower and eventually crash. I really think that closing the photosWindow should release all the memory it uses, rather than leaking. Also please test this using the real device and NOT the simulator.
I wanted to mention that the last code post is using suggestions made by folks in the Q&Q forum...to call photosWindow.close on the close event and to use a single HttpClient.
Also when the memory gets really low I see things like this in the debug console in XCode:
[INFO] Due to memory conditions, 0 of 3244 images were unloaded from cache.
Why would it unload 0 images if it got a memory warning? Seems like this is a big issue too.
Once again, not picking up the github commit.
TESTING:
There are two levels of testing that need to be conducted.
INSTRUMENTS
W/OUT INSTRUMENTS
(from [10c2ba87ab69e00ee963e38bd272ab5c8438aec4]) [#3166] Properly handle the case where modalDelegate is 'self', which is pretty much always. https://github.com/appcelerator/titanium_mobile/commit/10c2ba87ab69e00ee963e38bd272ab5c8438aec4"> https://github.com/appcelerator/titanium_mobile/commit/10c2ba87ab69...
Would it be possible to back port this to 1.6.x? We cannot wait until the end of May for 1.7
You can just get a CI build or pull directly from github. This will not be backported to 1.6.x.
No longer able to reproduce with iPhone 4, iOS 4.3.3. KS 1.7.0, build 1.7.0.879871b. Used the 3rd added code, but used instruments to monitor memory. Opened the thumbnail view repeatedly for over 5 mins. Memory leak not detected. Closing.