nativescript-bitmap-factory icon indicating copy to clipboard operation
nativescript-bitmap-factory copied to clipboard

iOS Extremely Large Memory Usage

Open NatanijelVasic opened this issue 6 years ago • 0 comments

Hello :)

Great plugin! I am using the resize function as described here for iOS and Android: (https://discourse.nativescript.org/t/how-can-i-resize-images/1336)

I noticed that I get a very large memory consumption during the resizing process, especially on iOS (I'm running iOS 12), as shown here: https://ibb.co/esx7rL

Am I doing something wrong?

function resizeAndEncodeImage(image){

    utilsModule.GC();

    console.log("resize start");

    var base64JPEG;
    var mutable = BitmapFactory.makeMutable(image);
    var bmp = BitmapFactory.create(image.width, image.height);

    console.log("resize 1");
    
    bmp.dispose(function(b) {

        b.insert(mutable);

        var b2; 

        if(application.ios){
            if(image.ios.scale == null){
                b2 = b.resizeHeight(compressedImageHeight);
            } else{
                b2 = b.resizeHeight(compressedImageHeight/(image.ios.scale));
            }
        }

        if(application.android){
            if(image.android.scale == null){
                b2 = b.resizeHeight(compressedImageHeight);
            } else{
                b2 = b.resizeHeight(compressedImageHeight/(image.android.scale));
            }
        }

        base64JPEG = b2.toBase64(BitmapFactory.OutputFormat.JPEG, 60); 

        b.dispose(function(){});
        b2.dispose(function(){});

    });

    utilsModule.GC();

    return base64JPEG;

}

Thanks so much for the help!! Natanijel Vasic

NatanijelVasic avatar Oct 16 '18 22:10 NatanijelVasic