#Leaks ###Setup Standard Ti environment
- OSX
- Node
- Ti SDK
- alloy/titanium from NPM
- Xcode/Instruments
Run instruments from Xcode, choose 'Allocations', your device, and the application to test.
Run your titanium project on your device.
When prompted to launch manually, press the record (red dot) button (or cmd+r) in Instruments.
Use the search box to watch specific processes. Before you start, hover over column names to get a summary of what they all mean (# Persistent is the one to watch). If your allocations only increase, your app is leaking memory.
###Attaching functions to views
Both of these implementations will leak
$.myCtrl.someFn = function() {}
OR
var myCtrl = Alloy.createController('myCtrl').getView();
myCtrl.someFn = function() {}
Any other property is fine
$.myCtrl.someValue = true;
If it is absolutely necessary to have a function attached to your controller's root view, you can set it to null or undefined when it's no longer needed
~~~myCtrl.js~~~
$.myCtrl.clickHandler = function(e) {
console.log(e);
};
~~~parentCtrl.js~~~
var myCtrl = Alloy.createController('myCtrl').getView();
$.parentCtrl.add(myCtrl);
...later...
myCtrl.clickHandler();
myCtrl.clickHandler = null;
Another solution to get parent controller functions to subcontrollers is to use the arguments variable
~~~parentCtrl.js~~~
var myCtrl = Alloy.createController('myCtrl', {someFn: function(data){...}});
$.parentView.add(myCtrl);
~~~myCtrl.js~~~
var args = arguments[0];
function clickHandler(e) {
args.somFn(e);
}