-1

I'm getting following error. I have tried android:largeHeap="true" and android:hardwareAccelerated="false". But still app is crashing and showing the same error

java.lang.OutOfMemoryError: Failed to allocate a 39306252 byte allocation with 16777216 free bytes and 27MB until OOM

at dalvik.system.VMRuntime.newNonMovableArray(Native Method)

at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
Zoe
  • 27,060
  • 21
  • 118
  • 148
Vinothini
  • 13
  • 4
  • 1
    `OutOfMemoryError in ANdroid Studio`. In Android Studio? Not in an Android app on your Android device? – greenapps Nov 15 '17 at 11:52
  • I think you are caching many image assets or something like that in your app. – Sudheesh R Nov 15 '17 at 11:53
  • 1
    refer this answer, you'll get an idea about OOM > https://stackoverflow.com/a/32245018/6630837 – Sudheesh R Nov 15 '17 at 11:55
  • https://stackoverflow.com/questions/32244851/androidjava-lang-outofmemoryerror-failed-to-allocate-a-23970828-byte-allocatio/32245018#32245018 – King of Masses Nov 15 '17 at 11:55
  • Possible duplicate of [Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM](https://stackoverflow.com/questions/32244851/androidjava-lang-outofmemoryerror-failed-to-allocate-a-23970828-byte-allocatio) – Giorgio Nov 15 '17 at 12:01

1 Answers1

1

if your BitMap size is large then you have to resize/rescale it to show it in your app otherwise OutOfMemory error will be thrown , you can try to use

android:largeHeap="true"

in your manifest or you have to manually resize them in your code ,have a look How to Resize a Bitmap in Android?

himel
  • 500
  • 5
  • 14
  • 1
    The OP already mentioned about `android:largeHeap="true"`. – Enzokie Nov 15 '17 at 11:54
  • Besides, `largeHeap` has no effect with large images, It's too big allocation over too short time, for large images the only thing that works is using something like Glide or Picasso. – Zoe Nov 15 '17 at 11:55
  • @Zoe, No. Just resizing/rescaling will do. That would be done by them too. – greenapps Nov 15 '17 at 11:58
  • @greenapps what if OP **wants** to have a massive image? In that case, resizing isn't an option and largeHeap can't possibly handle it – Zoe Nov 15 '17 at 11:58
  • Indeed. But then Glide and Picasso wil not master either. – greenapps Nov 15 '17 at 11:59
  • @greenapps It won't work perfectly, but it still does better than just using `largeHeap`. – Zoe Nov 15 '17 at 11:59
  • @Enzokie when i answered it wasn't , it was edited after may be. – himel Nov 16 '17 at 05:29
  • @himel it's already in the question from the beginning, the edit history shows it. – Enzokie Nov 16 '17 at 05:40