Problem
Tapping the tab's button to return to the root window of the tab orphans any windows between the current window and the root window.
Why This Is A Problem
Orphaned windows equate to leaked memory.
Expected Behavior
Tapping the tab's button should close every window that is open on that tab's stack, not just the current window.
Reproduction
Drop the following in an app.js. Touch "S1: Touch Me", then "S2: Touch Me". Notice in the log which windows were opened, and which were closed.
var tabGroup = Ti.UI.createTabGroup();
function openWindowOnStack(i) {
var win = Ti.UI.createWindow({
title: 'I Am ' + i
});
win.addEventListener('open', function() {
Ti.API.info('opened ' + i + '!');
if (i < 4) {
openWindowOnStack(i + 1);
}
});
win.addEventListener('close', function() {
Ti.API.info('closed ' + i + '!');
});
tab.open(win);
}
var outer = Ti.UI.createWindow({
title: 'I Am Parent',
rightNavButton: Ti.UI.createButton({ title: 'S1: Touch Me' })
});
var tab = Ti.UI.createTab({
window: outer, title: 'S2: Touch Me'
});
tabGroup.addTab(tab);
outer.rightNavButton.addEventListener('click', function() {
openWindowOnStack(0);
});
tabGroup.open();
Current Output
[INFO] opened 0!
[INFO] opened 1!
[INFO] opened 2!
[INFO] opened 3!
[INFO] opened 4!
[INFO] closed 4!
Expected Output
[INFO] opened 0!
[INFO] opened 1!
[INFO] opened 2!
[INFO] opened 3!
[INFO] opened 4!
[INFO] closed 3!
[INFO] closed 2!
[INFO] closed 1!
[INFO] closed 0!
Workaround
By following the three rules at the top of this app.js, I am able to clean up any orphaned windows.note to QE - this may not fit easily into current template.
Tested on Ti Studio 1.0.7.201112080131 Ti Mob SDK 1.8.0.1.v20111208124750 OSX Lion iPhone 4S OS 5.0.1 Expected behavior is shown