[TIMOB-8932] iOS: Memory leak with tabGroup
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2012-05-04T13:56:44.000+0000 |
Affected Version/s | Release 2.0.1 |
Fix Version/s | Release 2.1.0, Sprint 2012-09 API |
Components | iOS |
Labels | api |
Reporter | Morten F. Thomsen |
Assignee | Sabil Rahim |
Created | 2012-04-24T02:52:42.000+0000 |
Updated | 2017-03-31T17:29:46.000+0000 |
Description
the following example allows for multiple open/close of the tabGroup - and each time, the number of proxys increase and are never reduced. Also, the actual references (TiUIView, TiUITabController, TiUIWindow) increase and never reduce.
Example Code:
// app.js
var oxi={};
Ti.include('appframework.js');
(function(){
var win = Ti.UI.createWindow();
var mainUI;
function terminateUI() {
mainUI.close();
mainUI = null;
Ti.App.removeEventListener('terminateUI', terminateUI);
win.open();
};
function launch() {
win.close();
mainUI = oxi.ui.createMainUI();
Ti.App.addEventListener('terminateUI', terminateUI);
mainUI.open();
}
win.addEventListener('click',launch);
win.open();
})();
// appframework.js
(function(){
oxi.ui = {};
oxi.ui.createMainUI = function() {
var tabGroup = Ti.UI.createTabGroup();
var tab1 = Ti.UI.createTab({
title:'Library',
window: Ti.UI.createWindow({
navBarHidden: true
})
});
var tab2 = Ti.UI.createTab({
title:'Settings',
window: Ti.UI.createWindow({
navBarHidden: true
})
});
tab1.window.add(Titanium.UI.createView({
backgroundColor: '#ffc'
}));
tab2.window.add(Titanium.UI.createView({
backgroundColor: '#ffc'
}));
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tab1.window.addEventListener('click',function(e){
Ti.API.info('clicked on win1');
Ti.App.fireEvent('terminateUI');
});
return tabGroup;
};
})();
By changing the terminateUI() function to the following, all references and proxies are removed, except the one for win (intentional, as it is not set to null) and the one for mainUI (unintentional, as it is set to null explicitly after closing the tabGroup):
function terminateUI() {
for (var tab=mainUI.tabs.length-1;tab>-1;--tab) {
mainUI.removeTab(mainUI.tabs[tab]);
}
mainUI.close();
mainUI = null;
Ti.App.removeEventListener('terminateUI', terminateUI);
win.open();
};
For subsequent runs (the code allows for open/close multiple times of the tabGroup) the proxy for the tabGroup is cleared - however, the FIRST proxy is never disposed of.
Cannot Reproduce. Tried Reproducing with master 2.0.1.848d711 on Xcode 4.3 running 5.1 sim on Lion. NOTE : i did see "tabgrouproxy" still staying around but after doing a "Simulate Memory Warning" on Simulator and it went away.
Closing ticket as I am unable to reproduce the issue using the following environment; iPhone 7 (10.2) MacOS 10.11.6 (15G31) Studio 4.8.1.201612050850 Ti SDK 6.0.3 GA Appc NPM 4.2.8 Appc CLI 6.1.0 Ti CLI 5.0.11 Alloy 1.9.5 Arrow 1.10.1 Xcode 8.2 (8C38) Node v4.6.0 Java 1.7.0_80