Hi All
This question may have been asked quite a few times but i havent managed to find anything that works for me.
First i have been using titanium for a while and love it, but as my apps are getting larger they are becoming really hard to manage and buggy keep crashing at random point and i really dont want to have to revert to objective c.
So i have been reading step by step through the titanium docs which granted i should have fully read through at the start instead of skimming through mainly http://docs.appcelerator.com/titanium/3.0/#!/guide/CommonJS_Modules_in_Titanium.
So now i have fully changed my structure to suit a commonjs module layout, but like with most javascript large applications this can be done in so many different ways i never now what is correct.
Also i want to implement garage collection on all my windows and code and wanted to have feedback on my project whether it is correct, my app currently goes up to about 50mb max on memory in xcode but doesnt seems to crash at that but i see about 12mb is a better size in the docs.
so first here is how i start all my projects in my app.js
(function() { //run database function here and add options to modules like sharekit. var ApplicationTabGroup = require('ui/ApplicationTabGroup'); var theTabGroup = new ApplicationTabGroup(); theTabGroup.open(); })();So i then load my tab group pretty basic so far following the kitchensink
function ApplicationTabGroup() { // create tab group var self = Titanium.UI.createTabGroup(); // // create base UI tab and root window // var win1 = Titanium.UI.createWindow({ title: 'Tab 1', backgroundColor: '#fff', url: 'ui/win1.js' }); var tab1 = Titanium.UI.createTab({ icon: 'KS_nav_views.png', title: 'Tab 1', window: win1 }); // // create controls tab and root window // var win2 = Titanium.UI.createWindow({ title: 'Tab 2', backgroundColor: '#fff', url: 'ui/win2.js' }); var tab2 = Titanium.UI.createTab({ icon: 'KS_nav_ui.png', title: 'Tab 2', window: win2 }); // // add tabs // self.addTab(tab1); self.addTab(tab2); self.setActiveTab(1); return self; }; module.exports = ApplicationTabGroup;Ok so this is where i would like some advice within my windows i usually have a navigation window say here is the code for win1.js
var self = Ti.UI.currentWindow; var navGroup = Titanium.UI.iOS.createNavigationWindow({ window: self }); var button = Titanium.UI.createButton({ title: 'Open Blue Window' }); button.addEventListener('click', function(){ var getWin3 = require('ui/win3'); // OK I PASS THRU THE NAV TO USE ON THE OTHER PAGE IS THIS BEST PRACTICE ITS SO I CAN OPEN THE NEXT WINDOW IN THE NAVGROUP??? var win3= new getWin3 ( navGroup ); navGroup .openWindow(win3, {animated:true}); }); self.add(button); // for garbage collect NOT SURE IF THIS IS RIGHT self.addEventListener('close', function(e){ self.remove(navGroup ); // view & button still exist navGroup = null; button = null; });Then i will have the button open a new window in the group win3.js
function win3(model) { var self = Titanium.UI.createWindow({ title: 'Tab 2', backgroundColor: '#fff' }); var button = Ti.UI.createButton({ // parameters go here... }); button.addEventListener('click', function(e){ var getWin4 = require('ui/win4'); // OK I PASS THRU THE NAV TO USE ON THE OTHER PAGE IS THIS BEST PRACTICE ITS SO I CAN OPEN THE NEXT WINDOW IN THE NAVGROUP??? var win4= new getWin4 ( model ); model.openWindow(win4, {animated:true}); }); var view = Ti.UI.createView({ // some parameters here... }); view.add(button); self.add(view); // for garbage collect NOT SURE IF THIS IS RIGHT self.addEventListener('close', function(e){ self.remove(view); // view & button still exist view = null; button = null; }); return self; }; module.exports = win3;I would really like some feedback from the main devs at titanium after using the structure above my apps are working so much better, but i will still get the odd crash every now and again and my memory seems to creep up slowly over long periods, some i have fixed by adding a setTimeout on data transfer from json feeds but that's for another post.
Any advice would be really helpful ;) thanks