I am starting a new Titanium application and want to use best practices and avoid memory leaks from get mode. I am new to CommonJS, as well as to the Titanium platform in general.
Unfortunately, it seems that all of the sample applications for titanium surround on Ti.include("/lib/module")instead of the newer recommended best practice require("/lib/module") .
I am worried about memory consumption from using CommonJS. From the CommonJS Modules in the Titanium documentation , it says that the modules will be cached, does that mean that if I ever get access to the module, all these functions suddenly remain in memory, even if they go beyond?
I started a new application with the following structure
/ctrl
/lib
/ui
/model
Here, my main application has one view of the toolbar style, which is freely structured as follows:
(function() {
var getMenuItem = require("/ui/main").getMenuItem;
var win = Titanium.UI.createWindow({
title:'Main',
backgroundColor:'#fff'
});
var nav = Ti.UI.iPhone.createNavigationGroup({
window:win
});
var sect;
var data = [];
sect = Ti.UI.createTableViewSection();
data.push(sect);
sect.add(getMenuItem("Customers",
require("/ctrl/account").createCustMainWindow));
sect.add(getMenuItem("Schedules",
require("/ctrl/schedule").createScheduleMainWindow));
sect.add(getMenuItem("Settings"));
var menu = Titanium.UI.createTableView({
style: Ti.UI.iPhone.TableViewStyle.GROUPED,
data:data
});
win.add(menu);
menu.addEventListener('click',function(e) {
if (e.rowData.createWindow) {
var win = e.rowData.createWindow(nav);
nav.open(win);
}
});
var navWindow = Titanium.UI.createWindow();
navWindow.add(nav);
navWindow.open();
})();
Any guidance on the proper design of the project is appreciated.
source
share