Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26091] Android:App shows out of memory error when trying to scale down an image using ti.imagefactory

GitHub Issuen/a
TypeBug
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterMostafizur Rahman
AssigneeYordan Banev
Created2018-06-05T08:12:43.000+0000
Updated2019-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:*

Run the test code.

click the button and take pictures

Keep taking pictures until the log shows the out of memory error. Normally, the error occurs after taking 7 to 8 pictures.

*Output:* On *android 8* it does not reproduce. The error shows on android *4.4.3*. Here's the output for both the devices: For console logs, check the [link](https://gist.github.com/jebunnaher/afe31413d47d899d4113b537e3d79cf6)

Comments

  1. Yordan Banev 2018-06-12

    [~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 for setImage, 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 the remove 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 the success callback of showCamera 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.
  2. Bryan Whitaker 2018-06-12

    Thank you so much. Those changes and suggestions worked great for me.
  3. Yordan Banev 2018-06-13

    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.

JSON Source