Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14926] iOS: Memory leak on window containing a Ti.UI.iPhone.NavigationGroup

GitHub Issuen/a
TypeBug
PriorityCritical
StatusResolved
ResolutionCannot Reproduce
Resolution Date2017-04-09T21:53:48.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsleak, memory, navgroup, navigationgroup
ReporterFokke Zandbergen
AssigneeUnknown
Created2013-08-02T07:02:15.000+0000
Updated2018-02-28T20:04:07.000+0000

Description

When I'm not using a Ti.UI.iPhone.NavigationGroup in my main/root application window, there will be a time I need to close the Ti.UI.Window wrapping the navigation group. But when I do, Instruments show it's leaking. Consider the following app.js:
function onClose(e) {
  Ti.API.info('Closed: ' + e.source._id);
}

function closeNav() {
  container.close();
  // Uncomment for 2nd test-case: child.close();
}

var application = Ti.UI.createWindow({
  backgroundColor: 'red'
});
application.addEventListener('click', function () {
  container.open();
});

var container = Titanium.UI.createWindow({
  _id: 'container',
  backgroundColor: 'green',
});
container.addEventListener('close', onClose);

var child = Titanium.UI.createWindow({
  _id: 'child',
  backgroundColor: 'blue',
  title: 'Window'
});
child.addEventListener('click', closeNav);
child.addEventListener('close', onClose);

var nav = Titanium.UI.iPhone.createNavigationGroup({
  window: child
});

container.add(nav);
application.open();
Now do the following:

Run the app.

Click the red application window to open the navigationgroup holding a blue window.

Click the blue window to close the window containing the navigationgroup.

The console will show the following after step 3:
[INFO] Closed: container
And instruments will report the following number of living TiUIWindow's after:

Living: 1 (the application window)

Living: 3 (the application, container and child windows)

Living: 2 (the application and child window I guess)

Now, if you uncomment line 7 and follow the same steps the console will show:
[INFO] Closed: container
[INFO] Closed: child
But instruments will still report the same. So I guess, the child is kept hostage by some other native object? I would expect that closing the container window should be enough to properly clean up, but even the following doesn't give different results:
function closeNav() {
  container.close();
  container.removeEventListener('close', onClose);
  container = null;
  child.close();
  child.removeEventListener('close', onClose);
  child.removeEventListener('click', closeNav);
  child = null;
  nav = null;
}

Comments

  1. Eduardo Gomez 2013-08-20

    Tested on 3.1.2.GA as well. Seeing UINavigationController not getting released (under Transitory column). Moved to main project to dig into this since docs says: "All [navigation groups](http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.iPhone.NavigationGroup) must have at least one root window that cannot be removed."
  2. Hans Knöchel 2017-04-09

    Not reproducible with Ti.UI.iOS.NavigationWindow.

JSON Source