钛合金手机,通过内存池释放内存

发布于 2024-12-18 01:06:22 字数 1385 浏览 1 评论 0原文

我正在尝试找到一种解决方案,使用我另一天发现的内存池函数来释放 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文