# APDE heap size,how to change allocated memory size?

**URL:** <https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333>\
**Category:** Processing for Android\
**Created:** [January 24, 2021, 9:09am UTC](https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333 "2021-01-24T09:09:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kvi](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Kvi](https://discourse.processing.org/u/Kvi)\
**Post date:** [January 24, 2021, 9:09am UTC](https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333/1 "2021-01-24T09:09:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 24, 2021, 9:25am UTC](https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333/2 "2021-01-24T09:25:21Z")

</div>

go to preferences:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bf6717c01883f6f835c25e2eab7d8e15107e5a8e.png)

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/254ec0541ac1693b5cb0e96ede26f5bfe4f1e0fa.jpeg)  
just increase it to whatever you need

---

<div class="post-metadata">

**Author:** ![Kvi](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Kvi](https://discourse.processing.org/u/Kvi)\
**Post date:** [January 24, 2021, 9:28am UTC](https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333/3 "2021-01-24T09:28:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 24, 2021, 9:39am UTC](https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333/4 "2021-01-24T09:39:23Z")

</div>

oh. I’ll look into that

---

<div class="post-metadata">

**Author:** ![Kvi](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Kvi](https://discourse.processing.org/u/Kvi)\
**Post date:** [January 24, 2021, 4:05pm UTC](https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333/5 "2021-01-24T16:05:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kvi](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Kvi](https://discourse.processing.org/u/Kvi)\
**Post date:** [January 25, 2021, 11:18am UTC](https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333/6 "2021-01-25T11:18:46Z")

</div>

Just tested again and it give me

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [January 30, 2021, 7:39pm UTC](https://discourse.processing.org/t/apde-heap-size-how-to-change-allocated-memory-size/27333/7 "2021-01-30T19:39:42Z")

</div>

@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…

```auto
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!
