钛合金手机,通过内存池释放内存
我正在尝试找到一种解决方案,使用我另一天发现的内存池函数来释放 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)
如果有人对此有更好的想法,谢谢。
I am trying to find a solution to release the memory on android using memorypool function I found another day. My problem is that I am not sure how to implement it. How to call that function and how to pass the window.children object in it. Here is the original function I found:
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();
}
Lets say I have a simple window and a few children in it. Shell I just call MemoryPool at the begining or I need to pass something into it like MemoryPool(obj)
Thank you if someone has better idea of it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论