简体   繁体   English

正确设置IntelliJ IDEA中的堆大小

[英]Setting heap size in IntelliJ IDEA correctly

I have this peculiar problem with running a Processing application in IntelliJ IDEA. 我在IntelliJ IDEA中运行Processing应用程序时遇到了这个特殊问题。 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.(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:331) at processing.core.PImage.saveImageIO(PImage.java:3117) at processing.core.PImage.save(PImage.java:3297) at OffScreenRender.stopRender(OffScreenRender.java:38) at 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) at java.lang.Thread.run(Thread.java:724) 线程“动画线程”中的异常java.lang.OutOfMemoryError:java.awt.image.Raster.createPackedRaster(Raster.java:467)中java.awt.image.DataBufferInt。(DataBufferInt.java:75)的Java堆空间java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)在java.awt.image.BufferedImage。(BufferedImage.java:331)处理处理时的processing.core.PImage.saveImageIO(PImage.java:3117)。 core.PImage.save(PImage.java:3297)位于OffScreenRender.stopRender(OffScreenRender.java:38)的MainVecField.draw(MainVecField.java:93)处理。处理.cack.Papplet.handleDraw(PApplet.java:2305)at at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)atprocess.core.PApplet.run(PApplet.java:2176)at java.lang.Thread.run(Thread.java:724)

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. 问题是,当我更改IntelliJ中的.vmoptions文件时,我得到相同的结果,它们没有任何效果。 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. IDE右下角的“内存”编号相应增加,但似乎不让我的应用程序分配更多内存。

When I run the processing application in the processing IDE I can manage to save much larger files by setting a large heap size. 当我在处理IDE中运行处理应用程序时,我可以设法通过设置较大的堆大小来保存更大的文件。

In IntelliJ nothing over 256mb seems to make a difference. 在IntelliJ中,超过256mb似乎没有什么区别。 So my question is how do I set a larger heap size in IntelliJ that allows my application to allocate more memory? 所以我的问题是如何在IntelliJ中设置更大的堆大小,允许我的应用程序分配更多的内存?

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()
    {
        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");
    }
}

Changing vmoptions file adjusts the memory used by IntelliJ, but what you're having here is a shortage of memory of JRE that is launched by IntelliJ to execute your application. 更改vmoptions文件可调整IntelliJ使用的内存,但您在此处所拥有的是由IntelliJ启动以执行您的应用程序的JRE内存不足。 You need to adjust the memory setting in VM options part of the Run/Debug configuration, for example: 您需要在运行/调试配置的VM选项部分中调整内存设置,例如:

在此输入图像描述

IntelliJ shows you the amount used and the current size of the heap. IntelliJ显示使用的数量和堆的当前大小。 You are trying to set the maximum which it does not show. 您正在尝试设置它未显示的最大值。

You can attach VisualVM to IntellIJ to see the maximum by running jvisualvm 您可以通过运行jvisualvm将VisualVM连接到IntellIJ以查看最大值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM