Android OutOfMemory when GC reports free memory? -


so i'm looking through log of oom failure see following:

05-15 14:18:15.801: d/dalvikvm(5425): gc_before_oom freed 12k, 63% free 18896k/49863k, paused 43ms, total 44ms 05-15 14:18:15.801: e/dalvikvm-heap(5425): out of memory on 25694224-byte allocation. 05-15 14:18:15.801: i/dalvikvm(5425): "asynctask #4" prio=5 tid=35 runnable 05-15 14:18:15.801: i/dalvikvm(5425):   | group="main" scount=0 dscount=0 obj=0x41f117e8 self=0x5db0f2c0 05-15 14:18:15.801: i/dalvikvm(5425):   | systid=5539 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1544307456 05-15 14:18:15.801: i/dalvikvm(5425):   | schedstat=( 0 0 0 ) utm=19 stm=2 core=0 05-15 14:18:15.801: i/dalvikvm(5425):   @ android.graphics.bitmapfactory.nativedecodebytearray(native method) 05-15 14:18:15.801: i/dalvikvm(5425):   @ android.graphics.bitmapfactory.decodebytearray(bitmapfactory.java:520) 

this looks weird me. why there oom on ~25mb allocation when have ~30mb available?

edit

the code goes through these steps:

  1. camera.takepicture(null,null,callback)
  2. inside callback send data asynctask processing/saving
  3. asynctask decodes byte array bitmap further rotation
  4. boom!

it seems bitmap allocating more available heap size. can monitor memory usage using eclipse mat or android studio.

i suggest scale down bitmap if larger required. use options.injustdecodebounds = true ensure app not kicked off memory because of bitmap allocation. try free resources app not displaying. free memory onpause call place.you should use gc call efficiently if needed. can use

drawable drawable = imageview.getdrawable(); if (drawable instanceof bitmapdrawable) {     bitmapdrawable bitmapdrawable = (bitmapdrawable) drawable;     bitmap bitmap = bitmapdrawable.getbitmap();     bitmap.recycle(); }  

to free resource imageviews.

you can set largeheap="true". force other app out of memory. how heap increase never know. depends on if app forced out of memory.

you have other option create separate process assign separately memory heap in application. have use process="your process name" within activity tag.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -