Setting heap size in IntelliJ IDEA correctly

I have this peculiar problem with running a Processing application in IntelliJ IDEA. I want to save a large image and to do this I run in to the following exception:

Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.( at java.awt.image.Raster.createPackedRaster( at java.awt.image.DirectColorModel.createCompatibleWritableRaster( at java.awt.image.BufferedImage.( at processing.core.PImage.saveImageIO( at at OffScreenRender.stopRender( at MainVecField.draw( at processing.core.PApplet.handleDraw( at processing.core.PGraphicsJava2D.requestDraw( at at

So clearly there is some memory allocation problem here. The problem is that when i change the .vmoptions files in IntelliJ I get the same results, they have no effect. The "memory" number at the lower right corner of the IDE increases accordingly but it does not seem to let my application allocate more memory.

When I run the processing application in the processing IDE I can manage to save much larger files by setting a large heap size.
In IntelliJ nothing over 256mb seems to make a difference. So my question is how do I set a larger heap size in IntelliJ that allows my application to allocate more memory?

Thank you for your help!

I attach the code for my project in case anyone wants to test it out:

import processing.core.*;

public class TestClassMain extends PApplet

    public static void main(String args[])
        PApplet.main(new String[] { "--present", "TestClassMain" });

    //Global variables
    OffScreenRender screenRender;
    int c = 0;

    //Variables for offScreenRender
    int resFactor = 10;
    boolean offScreenRenderSwitch = false;

    public void setup()

        //Initialize the render object
        screenRender = new OffScreenRender(this, 11000, 7950, resFactor);

    public void draw()

        //Check if the render should be saved
        if(offScreenRenderSwitch == true){screenRender.startRender();}

        if(offScreenRenderSwitch == true)
            offScreenRenderSwitch = false;
        c += 2;

    public void keyPressed()
        //Render the graphics to an offScreen buffer
        offScreenRenderSwitch = true;

import processing.core.*;

 * Renders the processingsketch to a .tif file at specified resolution.

public class OffScreenRender
    PApplet parent; // The parent PApplet
    PGraphics render;
    int width;
    int height;
    int resFactor;

    OffScreenRender(PApplet p, int width_, int height_, int resFactor_)
        //Initialize variables
        parent = p;
        width = width_;
        height = height_;
        resFactor = resFactor_;

        render = parent.createGraphics(width, height);

    //Render the image
    void startRender()
        PApplet.println("first step");

    //Render the image
    void stopRender()
        PApplet.println("second step");"hej");
        PApplet.println("final step");
1 comment
Comment actions Permalink

I found the solution by setting the vm options in the run/debug configuration. That seemed to allocate more memory to the JRE and not the IDE...


Please sign in to leave a comment.