Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8094] Android: App crashes on the device while uploading images, Memory issues

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-05-03T17:28:18.000+0000
Affected Version/sRelease 1.8.2
Fix Version/sn/a
ComponentsAndroid
LabelsSupportTeam, core
ReporterDevang Gandhi
AssigneeAllen Yeung
Created2012-03-19T17:18:52.000+0000
Updated2017-03-10T00:06:38.000+0000

Description

The app uses camera to click pictures, and upload to their server. Before uploading they perform image compression and resizing. Ti.imagefactory module is used for these purposes. The pictures are high resolution images, taken by a 8MP camera on the Motorola Droid X. The issue arises, when he uploads more than 1 image or multiple similar images or displaying the image in imageview. He gets "Unable to load bitmap.Not enough memory.bitmap size exceeds VM budget." error on the device. You can see the crash log here
03-19 10:32:54.837: E/dalvikvm-heap(3474): 5752604-byte external allocation too large for this process.
03-19 10:32:54.916: E/GraphicsJNI(3474): VM won't let us allocate 5752604 bytes
03-19 10:32:54.916: D/dalvikvm(3474): GC_FOR_MALLOC freed 0K, 47% free 9431K/17479K, external 11586K/13634K, paused 73ms
03-19 10:32:54.923: E/TiDrawableReference(3474): (main) [1277,430400] Unable to load bitmap. Not enough memory: bitmap size exceeds VM budget
03-19 10:32:54.923: E/TiDrawableReference(3474): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.graphics.Bitmap.nativeCreate(Native Method)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.graphics.Bitmap.createBitmap(Bitmap.java:507)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.graphics.Bitmap.createBitmap(Bitmap.java:474)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:379)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.titanium.view.TiDrawableReference.getBitmap(TiDrawableReference.java:558)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at ti.modules.titanium.ui.widget.TiUIImageView.setImage(TiUIImageView.java:736)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at ti.modules.titanium.ui.widget.TiUIImageView.processProperties(TiUIImageView.java:849)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:641)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:464)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:456)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:434)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.titanium.proxy.TiViewProxy.handleToImage(TiViewProxy.java:716)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:303)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.os.Handler.dispatchMessage(Handler.java:95)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.kroll.common.TiMessenger.dispatchMessage(TiMessenger.java:318)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.kroll.common.TiMessenger.dispatchPendingMessages(TiMessenger.java:303)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.kroll.common.TiMessenger$2.getResult(TiMessenger.java:188)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.kroll.common.TiMessenger.sendBlockingMessage(TiMessenger.java:215)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.kroll.common.TiMessenger.sendBlockingRuntimeMessage(TiMessenger.java:143)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.kroll.KrollProxy.fireSyncEvent(KrollProxy.java:417)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at org.appcelerator.titanium.TiBaseActivity.onRestart(TiBaseActivity.java:830)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.app.Instrumentation.callActivityOnRestart(Instrumentation.java:1139)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.app.Activity.performRestart(Activity.java:3865)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.app.Activity.performResume(Activity.java:3876)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2191)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2228)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.os.Looper.loop(Looper.java:123)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at android.app.ActivityThread.main(ActivityThread.java:3806)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at java.lang.reflect.Method.invokeNative(Native Method)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at java.lang.reflect.Method.invoke(Method.java:507)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-19 10:32:54.923: E/TiDrawableReference(3474): 
at dalvik.system.NativeStart.main(Native Method)
03-19 10:32:54.923: I/TiUIHelper(3474): (main) [8,430408] view does not have parent, calling layout
Created sample apps, using the ti.imagefactory module, but could not reproduce this issue. Also tested the code on Motorola Droid3, LG OptimusV but still could not reproduce the issue.

Comments

  1. Neeraj Gupta 2012-03-19

    @Devang - This is not really a platform issue if the bitmap is larger than the OS can handle. Pedro was running into the same problem with his app so check with him how he solved it.
  2. Hieu Pham 2012-03-20

    I will test this as my personal device is a Droid X.
  3. Hieu Pham 2012-03-21

    On the Droid X, we were able to reproduce this issue. According to DDMS, the app was trying to store 16mb worth of images (2x 2.2mb + 2x 5.7 mb) at the same time. The memory is consistent at roughly 5-7mb the entire time, and there are no signs of leakage. Since this is happening randomly - could happen after the 2nd image, or up to 5th image, it's probably a timing bug. The cause is yet to be determined and would need further investigation on the application side. Also note that this behavior doesn't happen on faster phones with 8mb Camera (like Galaxy S2).
  4. Hieu Pham 2012-04-02

    The error you are seeing matches the error in timob-8432. Could be a duplicate.
  5. Bill Dawson 2012-04-18

    Just a quick note that i spent some time testing as well in 1.8.2, 2.0.1, and 2.1.0, on an HTC Desire (Android 2.2) using a jpg that is 1024x731 at 72DPI. I was using Devang's test (a few comments ago) but modified to use ImageFactory.compressToFile since the customer code above showed that. I also changed the ratio to 80/100 since their code does that when it's Android running. I did the compression test numerous times in succession on all three Titanium versions and never had any problem.
  6. Lee Morris 2017-03-10

    Closing this ticket as the issue cannot be reproduced.

JSON Source