Nativescript 在循环中调用promise时如何防止内存泄漏

Nativescript 在循环中调用promise时如何防止内存泄漏,nativescript,Nativescript,我好像犯了个错误 ActivityManager:进程nl.xxxx.yyyy(pid 21526)已 死亡:fore TOP(2411292)活动经理:Sethasoverayui呼叫 未知pid:21526 当我在循环中调用下面提到的函数时。在大约200次呼叫中出现错误。它看起来不像是一个计时问题,因为即使我在3秒钟的超时时间(在pomise返回后)调用该函数,它也会在大约200个周期后消失。我尝试将所有变量放在函数之外,将变量设置为null,但似乎没有任何帮助。我用谷歌搜索了一下手指的骨头

我好像犯了个错误

ActivityManager:进程nl.xxxx.yyyy(pid 21526)已 死亡:fore TOP(2411292)活动经理:Sethasoverayui呼叫 未知pid:21526

当我在循环中调用下面提到的函数时。在大约200次呼叫中出现错误。它看起来不像是一个计时问题,因为即使我在3秒钟的超时时间(在pomise返回后)调用该函数,它也会在大约200个周期后消失。我尝试将所有变量放在函数之外,将变量设置为null,但似乎没有任何帮助。我用谷歌搜索了一下手指的骨头,但什么也没找到。。。有人知道我需要做什么吗

function testrun(f)
{
        // initially called with f = 0
        if(f > 500) return; // limit test to 500 cycles
        console.log ("fire :"+ f); // show the cycle you're in
        getMyThumb("/storage/emulated/0/DCIM/Screenshots/Screenshot_20190710-092009_ScanApp.jpg")
        .then( thumb =>
        {
            console.log(thumb);
            setTimeout(() => 
            {
                testrun(f+1);
            }, 5000);   // tried setting timeout from 100ms to 5 seconds per cycle... All bugg out at ca. 200 cycles            
        })
        global.gc(); // testd with\ without  garbage collection     
}


global.getMyThumb = function name(filepath) 
{
    return new Promise((resolve, reject)=>
    {
       global.gc(); // tried with \ without   garbage collection here 
       imageSource = imageSourceModule.fromFile(filepath);
        try
        {
            var mutable = BitmapFactory.makeMutable(imageSource); 
            var ThumbBitmap = BitmapFactory.asBitmap(mutable).dispose((bmp) =>
            {   
                var optisizestring = "25,25";
                test =  bmp.resize(optisizestring); 
                base64JPEG = test.toBase64(BitmapFactory.OutputFormat.JPEG, 75);
                img = imageSource.fromBase64(base64JPEG);
                resolve( "data:image/png;base64," + base64JPEG);                
                global.gc(); // tried with \ without   garbage collection here
             });
        } catch(ex) { console.log("errds " + ex); resolve (null);}
    });
}

处理位图时,您可能需要更多内存,是否尝试在应用程序标记上设置
android:largeHeap=“true”
。尝试调用imageSources上的
recycle()
以从内存中释放位图:。Nativescript的ImageSource似乎从未调用过它。我将largeHeap设置为“true”,但这没有什么区别。recycle()不起作用。我有一个更高的版本(3.0 apk),但回收不是一个公认的功能…BitmapFactory.Options.inBitmap在我的情况下也不起作用。我的代码不重用任何位图。我从DCIM目录中获取文件,并在其中显示缩略图。上面的函数返回我从imageSource获取的图像的base64JPEG。(imageSource=imageSourceModule.fromFile(filepath);)所以它可以从内存中删除或重新使用,但不知何故它会留在内存中。。。