Problem Description
When using the imageAsResize function in blob, it will start eventually to fail with a warning message about no more memory available.
Test Code
var count = 0;
var win = Ti.UI.createWindow({
backgroundImage : 'b1.png',
layout : 'vertical'
});
var closeBtn = Ti.UI.createButton({
title : 'close',
top : '44dp',
});
var resizeBtn = Ti.UI.createButton({
title : 'resize: ' + count,
top : '20dp',
});
var imageView = Ti.UI.createImageView({
width : '200dp',
height : '200dp',
});
//--
win.add(closeBtn);
win.add(resizeBtn);
win.add(imageView);
//--
resizeBtn.addEventListener('click', function() {
var f = Ti.Filesystem.getFile('b1.jpg');
var blob = f.read();
f = null;
win.remove(imageView);
imageView.view = null;
imageView = null;
imageView = Ti.UI.createImageView({
width : '200dp',
height : '200dp',
});
imageView.image = blob.imageAsResized(960, 960);
blob = null;
win.add(imageView);
count++;
resizeBtn.title = 'resize: ' + count;
});
closeBtn.addEventListener('click', function() {
win.close();
});
win.open();
Attachments
Check the attachments for b1.jpg
Steps to reproduce
1. Create mobile project (classic titanium)
2. Copy-Paste the code from the testcase into app.js
3. Copy bg1.jpg into Resources directory
4. Deploy into device
5. Click in resize until the image doesn't appear anymore.
Extra info
when the image doesn't appear anymore, you will see a message in the console saying:
[ERROR] : TiBlob: (KrollRuntimeThread) [3227,231234] Unable to resize the image. Not enough memory: null
[ERROR] : TiBlob: java.lang.OutOfMemoryError
[ERROR] : TiBlob: at android.graphics.Bitmap.nativeCreate(Native Method)
[ERROR] : TiBlob: at android.graphics.Bitmap.createBitmap(Bitmap.java:809)
[ERROR] : TiBlob: at android.graphics.Bitmap.createBitmap(Bitmap.java:786)
[ERROR] : TiBlob: at android.graphics.Bitmap.createBitmap(Bitmap.java:718)
[ERROR] : TiBlob: at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:594)
[ERROR] : TiBlob: at org.appcelerator.titanium.TiBlob.imageAsResized(TiBlob.java:543)
[ERROR] : TiBlob: at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] : TiBlob: at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:64)
[ERROR] : TiBlob: at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:884)
[ERROR] : TiBlob: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1107)
[ERROR] : TiBlob: at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:327)
[ERROR] : TiBlob: at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] : TiBlob: at android.os.Looper.loop(Looper.java:136)
[ERROR] : TiBlob: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[INFO] : I/dalvikvm-heap: Grow heap (frag case) to 182.277MB for 1474561
Q&A Link
http://developer.appcelerator.com/question/162431/android-memory-leaks
I am also having this problem and news...
PR: https://github.com/appcelerator/titanium_mobile/pull/7197 In addition to
imageAsResized
,imageAsThumbnail
,imageWithAlpha
,imageWithRoundedCorner
andimageWithTransparentBorder
were also fixed to the memory from growing too large. Test code as above. Please test with other images and the other methods as well. The b1.jpg is quite large in general, hence for the other methods that do not resize, use a smaller image to test Alpha, Rounded Corner and TransparentBorder.I'm glad this is fixed. It would be nice if you guys would implement support for
camera.getParameters.setPictureSize()
in the native camera module to help with memory problems like this. I created a module for this because the Titanium camera module resulted in too many memory errors. See https://github.com/skypanther/picatsize -- which is essentially TiCamera with a few modifications. Feel free to use whatever you want from it.[~timpoulsen] Thanks. I'll try to take a look into your code.
Verified the fix. 1.Tested the
imageAsResized
&imageAsThumbnail
with the attached image which is around 1.9MB. 2.Tested the imageWithAlpha,
imageWithRoundedCornerand
imageWithTransparentBorder` with a smaller image as these don't resize. Did not see any out of memory errors in any case with the fix. Closing. Environment: Appc Studio : 4.3.1.201509302304 Ti SDK : 5.1.0.v20151014101225 Ti CLI : 5.0.5 Alloy : 1.7.16 MAC Yosemite : 10.10.5 Appc NPM : 4.2.1-1 Appc CLI : 5.1.0-38 Node: v0.10.37 Android 4.2.2