0

I have a pair of background images for both vertical and horizontal layout on my Android app. They are jpeg images with a total size of 236 KB combined.

I keep running out of memory though, with the error message "Out of memory on a 23047212-byte allocation".

How can I have a resource demanding 23 MB of allocation with the background images being a total of 236 KB?

The problem is only present when using the background images in my activities.

Petter
  • 773
  • 2
  • 9
  • 19

2 Answers2

0

The size of the image file in KB is not directly relevant to this issue, but the size of the image in pixels along other factors as well. So if you want to reduce memory consumption, the easiest way would be to use images with smaller dimensions.

This question might help you:

Android background image memory usage

Community
  • 1
  • 1
SuperFrog
  • 7,631
  • 9
  • 51
  • 81
  • The images are 1067 × 600 and 600 x 1067, so not that big really. Shoudn't it be possible to use background images this size and larger? (in case of bigger devices). Any lower resolution, and they would look horrible. – Petter Sep 01 '15 at 16:32
  • Thanks for the link. Placing the images in a drawable-nodpi folder seems to have solved the problem :) – Petter Sep 01 '15 at 16:59
0

Another issue is that Android does not release native arrays, used for images data, automagically in a same way as it does for other java objects in GC time. Imho you need to track number of refs and release them yourself. But only in case you have a lot of new images all the time. Something like a very long list of pictures or users with avatars. Or may be your background is loading again and again.

Cynichniy Bandera
  • 5,991
  • 2
  • 29
  • 33