Set Heap Size Correctly in IntelliJ IDEA

I have this difficult problem launching a processing application in IntelliJ IDEA. I want to save a large image, and for this, I ran the following exception:

An exception was thrown in the Animation Theme thread java.lang.OutOfMemoryError: Java heap space in java.awt.image.DataBufferInt. (DataBufferInt.java:75) in java.awt.image.Raster.createPackedRaster (Raster.java:467) in java.awt.image.DirectColorModel.createCompatibleWritableRaster (DirectColorModel.java:1032) in java.awt.image.Bered (BufferedImage.javahaps31) at processing.core.PImage.saveImageIO (PImage.javahaps117) while processing .core.PImage.save (PImage.java:3297) in OffScreenRender.stopRender (OffScreenRender.java:38) on MainVecField .draw (MainVecField.java:93) at processing.core.PApplet.handleDraw (PApplet.java:2305) at processing.core.PGraphicsJava2D.requestDraw (PGraphicsJava2D.java:243) at processing.core.PApplet.run (PApplet. java: 2176) in java.lang.Thread.run (Thread.java:724)

So itโ€™s clear that there is a problem with memory allocation. The problem is that when I change .vmoptions files in IntelliJ, I get the same results, they have no effect. The number of "memory" in the lower right corner of the IDE increases accordingly, but it does not seem to allow my application to allocate more memory.

When I run the processing application in the processing IDE, I can save much larger files by setting a large heap size.

In IntelliJ, nothing more than 256 MB seems to matter. So my question is: how to set a large heap size in IntelliJ, which allows my application to allocate more memory?

Thank you for your help!

I am attaching code for my project if someone wants to check 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() { size(1000,700); background(0); stroke(255); //Initialize the render object screenRender = new OffScreenRender(this, 11000, 7950, resFactor); } public void draw() { frameRate(30); stroke(255); //Check if the render should be saved if(offScreenRenderSwitch == true){screenRender.startRender();} background(0,0,0); rect(20+c,height/2,60,60); if(offScreenRenderSwitch == true) { screenRender.stopRender(); 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() { parent.beginRecord(render); render.scale(resFactor); PApplet.println("first step"); } //Render the image void stopRender() { parent.endRecord(); PApplet.println("second step"); render.save("hej"); PApplet.println("final step"); } } 
+7
java intellij-idea processing processing-ide
source share
2 answers

Modifying the vmoptions file allows you to customize the memory used by IntelliJ, but what you have here is the lack of JRE memory that IntelliJ runs to run your application. You need to adjust the memory setting in the part of the VM parameters in the "Run / Debug" configuration, for example:

enter image description here

+32
source share

IntelliJ shows you the amount used and the current heap size. You are trying to set a maximum that it does not show.

You can connect VisualVM to IntellIJ to see the maximum by running jvisualvm

+2
source share

All Articles