- Application type: mobile
- Titanium SDK: 3.1.1.GA
- Platform and Version: iOS 6.1
- Device: iOS Simulator
- Host Operating System: OSX 10.8.4
- Titanium Studio: 3.1.1.201306112235
parent_controller.js:
_.each(category, function(inventory_item, index, list) { var row = Alloy.createController('inventory_list_row', { selectedBackgroundColor: '', data: inventory_item }); row.destroy(); row = null; }); Ti.App.fireEvent('checkIn');
inventory_list_row.js:
Ti.App.addEventListener('checkIn', function(e) { console.info('Checking In: ' + args.data.title); });
Foreword: The above code is irrigated to prove the point. I know that it really does nothing, but it is really problematic.
The code in parent_controller.js may run several times depending on the user interaction in my Titanium Mobile iPad application. If the code above only works once, everything will be fine. Each time the above code is run, the previous controllers are some of them left in memory and still exciting events.
For example, suppose that the first time the code is run, 3 inventory_list_row controllers are generated. In the console, I will see that the messages "Checking In" are displayed as expected. The second time it starts, I will see that the message βChecking Inβ appears in the console, etc. etc.
Why is this, and what can I do to prevent it? You can see that I tried using .destroy and setting the string to zero to no avail.
source share