APDE heap size,how to change allocated memory size?

Hi
I my tying to make simple game,but have a trouble with java.lang.OutOfMemoryError.
My sketch by default (without any P2D,P3D) uses about 40 000 000 bytes,but i have 4gb ram and need minimum 100mb,when i am using P2D the total memory decreases to 24 000 000.
How to change the heap size in APDE sketch?

Thanks.

go to preferences:

image
just increase it to whatever you need

Thanks for fast reply, but i need to do that in APDE(android)

oh. I’ll look into that

I just have tested again and changed the size of my image downto 25%(now about 5000x5000) and this worked.
It seems that android mode automatically changes the memory allocation.(now about 170 000 000).

I saw that i can’t load big images like 10000 x 5000.

P.S. without using P2D,P3D.

Just tested again and it give me

java.lang.OutOfMemoryError: Failed to allocate a 738736 byte allocation with 393816 free bytes and 384KB until OOM, max allowed footprint 268435456, growth limit 268435456
	at processing.core.PImage.init(PImage.java:162)

@Kvi
Your issue is available heap memory. This is restricted by Android and varies between devices. As soon as you try to use more than allowed you will get this memory error.

You can monitor how much memory your app is using and how much it is allowed to use. The following sketch shows how…

final Runtime runtime = Runtime.getRuntime(); 

int fontSize ;
ArrayList <TestObject> arrayList ;

void setup() {
  fullScreen();
  arrayList = new ArrayList<TestObject>() ;
  fontSize = width/16 ;
  textSize(fontSize);
  textAlign(CENTER, CENTER) ;
}


void draw() {
  background(0);
  fill(255);
  text("heap size = " + runtime.maxMemory()/1048576 +" MB", 10, 0, width, fontSize) ;
  text("allocated memory = " + runtime.totalMemory()/1048576 + " MB", 10, 2*fontSize, width, fontSize);
  text("arrayList total = " + 10*arrayList.size() + " MB", 10, 4*fontSize, width, fontSize);
}

void mousePressed() {
  arrayList.add(new TestObject()); //add 10MB
}

class TestObject {
  byte[] testArray ;
  TestObject(){
    testArray = new byte[10*1048576]; //10MB
  }
}

Keep tapping the screen … you will see the allocated memory increase to allow the adding of new objects … until you reach the max allowed!

1 Like