[TIMOB-26091] Android:App shows out of memory error when trying to scale down an image using ti.imagefactory
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Mostafizur Rahman |
Assignee | Yordan Banev |
Created | 2018-06-05T08:12:43.000+0000 |
Updated | 2019-11-08T13:21:54.000+0000 |
Description
*Issue Description:*
I have an app where I am getting out of memory errors when
trying to scale down an image on Android. It doesn't happen every
single time, but more times than not. What I am doing is taking the picture and then I want to resize it and upload it to a server using *ti.imagefactory.*
*Test Environment:*
Real device: Huawei Y9 2018(android 8),HTC one android 4.4.2
Appcelerator Command-Line Interface, version 7.0.3
Copyright (c) 2014-2018, Appcelerator, Inc. All Rights Reserved.
Operating System
Name = Mac OS X
Version = 10.13.2
Architecture = 64bit
CPUs = 4
Memory = 8.0GB
Node.js
Node.js Version = 8.9.1
npm Version = 5.5.1
Appcelerator CLI
Installer = 4.2.13
Core Package = 7.0.3
Titanium CLI
CLI Version = 5.1.0
node-appc Version = 0.2.44
Titanium SDKs
7.1.1.GA
Version = 7.1.1
*Test Code:* Check the [link](https://gist.github.com/MotiurRahman/f5f2392af6f010d22c0d199fa9545124).
*Test Steps:*
[~morahman] This slightly reworked sample should get rid of the memory leak: https://gist.github.com/ypbnv/066245e8a5b4fc4c293a3df60e6c652c Using directly
e.media
as a TiBlob to be passed as parameters forsetImage
,ImageFactory.imageAsResized
and calculating reduced dimensions has the same result and goes easier on the memory allocation. Another thing that I noticed is that here: https://gist.github.com/MotiurRahman/f5f2392af6f010d22c0d199fa9545124#file-app-js-L74 The parameter passed for theremove
method on both ImageViews is an instance of TiBlob, but it expects an instance of TiView. As for the memory leak itself - I don't think it is specific for the ImageFactory module. I was able to reproduce it without the module at all. Allocating multiple big chunks of memory in thesuccess
callback ofshowCamera
seems to be the culprit. Doing the same work outside the callback works just fine, so I would recommend more complex usage of the camera result to be done outside the callback's context.Thank you so much. Those changes and suggestions worked great for me.
We have a work in progress about improving memory management with images. Once it is ready this ticket's test case will be tested once again for possible leaks.