我正在尝试使用另一天发现的 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 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();
}
假设我有一个简单的窗口和几个孩子。Shell 我只是在开始时调用 MemoryPool 或者我需要将一些东西传递给它,比如 MemoryPool(obj)
如果有人对此有更好的想法,谢谢。