Eclipse memory settings when getting “Java Heap Space” and “Out of Memory”

前端 未结 11 754
野的像风
野的像风 2020-11-27 13:06

When trying to launch and run a flex/java project in eclipse I kept getting a \"Out of Memory Exception\" and \"Java Heap Space\" using Eclipse, Tomcat and a JRE.

Wh

相关标签:
11条回答
  • 2020-11-27 13:24

    -xms is the start memory (at the VM start), -xmx is the maximum memory for the VM

    • eclipse.ini : the memory for the VM running eclipse
    • jre setting : the memory for java programs run from eclipse
    • catalina.sh : the memory for your tomcat server
    0 讨论(0)
  • 2020-11-27 13:25

    I have these settings:

    -vmargs
    ...
    -Duser.name=...
    -XX:PermSize=256m
    -XX:MaxPermSize=256m
    -Xmn128m
    -Xms256m
    -Xmx768m
    

    Eclipse randomly crashed before I set the PermSize equal to MaxPermSize.

    0 讨论(0)
  • 2020-11-27 13:26

    We hit a heap space issue with Ant while trying to build a very large Flex project which could not be solved by increasing the memory allocated to Ant or by adding the fork=true param. It ended up being a bug in Flex 3.4.0 sdk. I finally figured this out after polling the devs for their sdk version and reverting to 3.3.0.

    For the curious.

    I tracked the bug down to an Interface file that had an additional accessor pair added "get/set maskTrackSkin". The heap space error hit if any additional functions were added to the interface and to make things worse the interface was not in the project that was getting the heap space error. Hope this helps someone.

    0 讨论(0)
  • 2020-11-27 13:27

    First of all, I suggest that you narrow the problem to which component throws the "Out of Memory Exception".

    This could be:

    1. Eclipse itself (which I doubt)
    2. Your application under Tomcat

    The JVM parameters -xms and -xmx represent the heap's "start memory" and the "maximum memory". Forget the "start memory". This is not going to help you now and you should only change this parameter if you're sure your app will consume this amount of memory rapidly.

    In production, I think the only parameter that you can change is the -xmx under the Catalina.sh or Catalina.bat files. But if you are testing your webapp directly from Eclipse with a configured debug environment of Tomcat, you can simply go to your "Debug Configurations" > "Apache Tomcat" > "Arguments" > "VM arguments" and set the -xmx there.

    As for the optimal -xmx for 2gb, this depends a lot of your environment and the number of requests your app might take. I would try values from 500mb up to 1gb. Check your OS virtual memory "zone" limit and the limit of the JVM itself.

    0 讨论(0)
  • 2020-11-27 13:34

    Found 2 issues in our case.

    1. The Memory was halting and we where mandatory to set the startup perm size to higher value. I guess it was using memory faster then able to allocate it. In our case. -XX:PermSize=256m -XX:MaxPermSize=256m

    2. We are using Clearcase and the plugin from Rational Clearcase SCM (7.0.0.2) was used in Eclipse. The plugin was the case of why Eclipse crashed. And at the moment we do not know why, but could be good to know for others. Was forced to disable it.

    0 讨论(0)
  • 2020-11-27 13:34

    If you see an out of memory, consider if that is plausible: Do you really need that much memory? If not (i.e. when you don't have huge objects and if you don't need to create millions of objects for some reason), chances are that you have a memory leak.

    In Java, this means that you're keeping a reference to an object somewhere even though you don't need it anymore. Common causes for this is forgetting to call close() on resources (files, DB connections, statements and result sets, etc.).

    If you suspect a memory leak, use a profiler to find which object occupies all the available memory.

    0 讨论(0)
提交回复
热议问题