저는 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를 다시 열면 메모리가 다시 할당됩니다. 이 때문에 내 app의 메모리 사용량은 videoPlayer가 시작될 때마다 증가합니다.
나는 내 사고 방식이 옳지 않다는 것을 알고 있습니다. 나는 여기서 아주 단순한 것을 간과하고있다. 누구든지 내가 옳은 일을하지 않는다는 것을 알려 줄 수 있습니까?
Titanium SDK는 어떤 플랫폼에서 사용합니까? –
최신 Titanium SDK (3.0)를 사용하고 있습니다. 그리고 iOS 용으로 구축하고 있습니다. – wiseindy
글쎄 거기에 관련된 문제가있었습니다. 일반적으로 3.0.2.GA로 수정해야합니다. 티타늄의 경우 [메모리 관리] (http://docs.appcelerator.com/titanium/latest/#!/guide/Managing_Memory_and_Finding_Leaks)를 이미 보았습니다. –