# textSize causing OutOfMemoryError

**URL:** <https://discourse.processing.org/t/textsize-causing-outofmemoryerror/2678>\
**Category:** Coding Questions\
**Created:** [August 16, 2018, 3:22am UTC](https://discourse.processing.org/t/textsize-causing-outofmemoryerror/2678 "2018-08-16T03:22:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![geek96boolean10](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/geek96boolean10/32/1118_2.png) [@geek96boolean10](https://discourse.processing.org/u/geek96boolean10)\
**Post date:** [August 16, 2018, 3:22am UTC](https://discourse.processing.org/t/textsize-causing-outofmemoryerror/2678/1 "2018-08-16T03:22:41Z")

</div>

I have a program that requires textSize to increase over time. When running it gradually, i.e. textSize(4),5,6,7,etc., the number can reach a very high value without anything bad happening. However, if I try to start off with a high value (the same number as gradually approached), it throws an OutOfMemory exception:

> java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:484) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.(DataBufferInt.java:75) at java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.awt.image.BufferedImage.(BufferedImage.java:324) at processing.core.PFont.(PFont.java:232) at processing.core.PFont.(PFont.java:337) at processing.core.PGraphics.createFont(PGraphics.java:4078) at processing.core.PApplet.createFont(PApplet.java:6254) at processing.core.PApplet.createDefaultFont(PApplet.java:6188) at processing.core.PGraphics.defaultFontOrDeath(PGraphics.java:8219) at processing.core.PGraphics.textSize(PGraphics.java:4391) at processing.core.PApplet.textSize(PApplet.java:12688) at recaman.draw(recaman.java:150) at processing.core.PApplet.handleDraw(PApplet.java:2418) at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:907) at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692) at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674) at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443) at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293) at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147) at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759) at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81) at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452) at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505)

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 16, 2018, 4:05am UTC](https://discourse.processing.org/t/textsize-causing-outofmemoryerror/2678/2 "2018-08-16T04:05:53Z")

</div>

Can you please post a [MCVE](https://stackoverflow.com/help/mcve) that demonstrates the problem?

---

<div class="post-metadata">

**Author:** ![EnhancedLoop7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/enhancedloop7/32/1040_2.png) [@EnhancedLoop7](https://discourse.processing.org/u/EnhancedLoop7)\
**Post date:** [August 16, 2018, 4:39pm UTC](https://discourse.processing.org/t/textsize-causing-outofmemoryerror/2678/3 "2018-08-16T16:39:03Z")

</div>

As @Kevin mentioned, posting an MCVE, or some code so we can see, would help us see your issue better. But, maybe I can help you out by explaining what the _OutOfMemory_ error is? You mention that it has to do with `textSize()`, and you also mentioned that you are trying to do something with increasing that over time. How are you doing it?

Do you have `textSize(variable)` and you have something like: `variable++` ? If that keeps on increasing, then you will eventually run out of memory. A way to fix that, would be limiting the amount that your variable can increase with an if statement or some other type of conditional.

That’s a start, and if you still aren’t able to get it working, we would have no problem helping out more, but just post the problematic code so we can help you further.

Hope this helps,

EnhancedLoop7
