OutOfMemoryError loading 3 images (1440x1920)

edited April 2014 in Android Mode

I have a strange issue. If I load 3 images (1440x1920 px) my tablet Samsung P7500 (1GB ram ) crash. The Samsung S4 too. With the same code, my Huawei Y300 (512MB ram) work fine until I load 15 images. Why? How can I resolve this problem and load at least 10 images? What is the problem? I must change some parameters?

I use the latest version of Processing 2.1.2, Android SDK Tools 22.6.2, Android SDK Build-Tools 19.0.3

thanks

//
// bg1.jpg 1440x1920 px

PImage[] img = new PImage[3];
void setup()
{
  for (int i=0; i<3; i++)
  {
    img[i]=loadImage("bg1.jpg");
    img[i].loadPixels();
  }
}
void draw()
{}

FATAL EXCEPTION: Animation Thread
java.lang.OutOfMemoryError
  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:574)
  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:640)
  at processing.core.PApplet.loadImage(Unknown Source)
  at processing.test.test.test.setup(test.java:26)
  at processing.core.PApplet.handleDraw(Unknown Source)
  at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
  at processing.core.PApplet.run(Unknown Source)
  at java.lang.Thread.run(Thread.java:856)
Tagged:

Answers

  • Sounds like you are exceeding the device max heap size... On a quick google search I think I found that the Huawei heap is 128MB but the Samsung is 48/64MB, These are the max amounts of memory your app can use (allocated by system). Having said that, I would have expected a few more images could be loaded on the Samsung, perhaps depends what else your app is doing to use up the allocated memory.

Sign In or Register to comment.