我正在使用Titanium Appcelerator來使用JavaScript開發應用程序。他們建議使用CommonJS方法。關於CommonJS的簡要例子可以參見here。管理CommonJS模塊的問題
對於我的生活,我仍然無法弄清楚如何構建我的代碼。
例子:
/* Homescreen.js */
exports.createHomescreen = function() {
//load all required modules first
var videoPlayer = require('ui/videoPlayerModule');
var self = Ti.UI.createWindow({
width:'100%',
height:'100%'
})
var newPlayer = videoPlayer.createPlayer({
width:100
height:50
});
self.add(newPlayer);
return self;
}
的videoPlayerModule
/* videoPlayerModule.js */
exports.createPlayer = function (object) {
//load all required modules first
var self = Ti.UI.createWindow({
width:object.width,
height:object.height
});
var exitVideoButton = Ti.UI.createButton({
width:100,
height:50
});
exitVideoButton.addEventListener('click',function(e){
self.close(); //When this window is closed, the memory isn't freed.
self = null; //Still the memory isn't cleared
});
self.add(exitVideoButton);
return(self);
}
我有,因爲每當我加載一個錄像機並關閉它,內存不會被清零內存分配問題。如果我再次打開videoPlayer,則會再次分配內存。因此,每次啓動videoPlayer時,我的應用程序的內存使用量都會增加。
我知道我的思維方式不對。我在這裏忽略了很簡單的事情。任何人都可以讓我知道我不正確的做法嗎?
您使用哪一個Titanium SDK以及哪個平臺? – 2013-04-07 09:46:06
我正在使用最新的Titanium SDK(3.0) 而我正在爲iOS構建 – wiseindy 2013-04-07 10:55:07
那麼是否有與此相關的問題。通常應該用3.0.2.GA來修正。我猜你已經看了一下Titanium的[內存管理](http://docs.appcelerator.com/titanium/latest/#!/guide/Managing_Memory_and_Finding_Leaks)。 – 2013-04-07 12:42:06