Javascript 钛合金手机,使用memorypool释放内存
我正试图找到一个解决方案,用我另一天发现的memorypool函数释放android上的内存。我的问题是,我不知道如何实施它。如何调用该函数以及如何在其中传递window.children对象。以下是我发现的原始函数:Javascript 钛合金手机,使用memorypool释放内存,javascript,android,memory-leaks,titanium-mobile,Javascript,Android,Memory Leaks,Titanium Mobile,我正试图找到一个解决方案,用我另一天发现的memorypool函数释放android上的内存。我的问题是,我不知道如何实施它。如何调用该函数以及如何在其中传递window.children对象。以下是我发现的原始函数: var MemoryPool = function() { var _window; /* Here we make our "auto-release" pool. It's simply a window. We hide it upon
var MemoryPool = function() {
var _window;
/*
Here we make our "auto-release" pool. It's simply a window.
We hide it upon creation so it won't interfere with our view hierarchy.
5/3/2011: It seems that the window does not need to be a subcontext, just a regular window will do.
*/
this.init = function() {
_window = Ti.UI.createWindow();
_window.hide();
_window.open();
}
// This is where we clear out the memPool by closing it then reopening it again.
this.clean = function(obj) {
if(obj instanceof Array) {
var arLen=obj.length;
for ( var i=0, len=arLen; i<len; ++i ) {
// We then stick the entire view into the pool
_window.add(obj[i]);
}
} else {
// We then stick the entire view into the pool
_window.add(obj);
}
Ti.API.info('Cleaning MemoryPool.');
// We empty the pool by closing it.
_window.close();
// We recreate the window again for the next object
this.init();
};
this.init();
}
var MemoryPool=function(){
var_窗口;
/*
在这里,我们创建了“自动发布”池。它只是一个窗口。
我们在创建时隐藏它,这样它就不会干扰我们的视图层次结构。
2011年5月3日:似乎窗口不需要是子文本,只需要一个常规窗口就可以了。
*/
this.init=函数(){
_window=Ti.UI.createWindow();
_window.hide();
_window.open();
}
//在这里,我们通过关闭memPool然后再次打开它来清除memPool。
this.clean=功能(obj){
if(阵列的obj实例){
var arLen=对象长度;
对于(var i=0,len=arLen;i