Created
September 30, 2011 21:25
-
-
Save jonalter/1255012 to your computer and use it in GitHub Desktop.
Memory Management Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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