Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created September 30, 2011 21:25
Show Gist options
  • Select an option

  • Save jonalter/1255012 to your computer and use it in GitHub Desktop.

Select an option

Save jonalter/1255012 to your computer and use it in GitHub Desktop.
Memory Management Example
// GLOBAL SCOPE
var win = Ti.UI.createWindow();
var parentView = Ti.UI.createView();
var childView = Ti.UI.createView();
parentView.add(childView);
win.add(parentView);
win.open();
// parentView and childView are not safe to release, as references still exist
win.remove(parentView);
// GLOBAL SCOPE
var win = Ti.UI.createWindow();
var parentView = Ti.UI.createView();
var childView = Ti.UI.createView();
parentView.add(childView);
win.add(parentView);
// childView is safe to release from memory, as it is no longer referenced. However, on the platform-side, the proxy and view remain in memory as they are internally referenced as sub-view objects.
childView = null;
win.open();
// The parentView reference is still live, so child views are internally retained until the parent reference no longer exists.
win.remove(parentView);
// parentView is safe to release from memory, as it is no longer referenced. Child views that are no longer referenced will also be released from memory.
parentView = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment