DISCLAIMER: I do not pretend to understand all the JVM options, much less how the JVM manages memory. The following is just a report on my experience that hopes to help others having similar problems.
I’m gonna post something quick before I forget about it because it was a major pain in the ass for me.
Since I’ve been writing primarily Java at SimpleGeo, I’ve been using IntelliJ IDEA, which is a great IDE. However, Malone and I started noticing that as time went along, the longer we had it open, the more it would start randomly stall.
Our guess is that because the IDE is written in Java, what we’re experiencing are GC storms and heap resizes, which bring the entire application to a grinding halt.
After googling around a bit, I was able to stop this from happening by adding the following runtime options
-Xms1024m -Xmx1024m -XX:MaxPermSize=1024m
Those 3 options basically tell IntelliJ to just allocate 1GB memory for itself no matter what. This is fine for us because we have 4GB laptops and the primary thing we’re doing on them is writing Java. Obviously any other size is fine, but the key is to make it allocate enough memory once and just stick to that. We are working with a decent-sized codebase, so 1GB suits us well. IntelliJ’s developers stated essentially the opposite here a few years back, but my experience does not correspond with their predictions. I’m guessing that if I ever get it to 1GB, THEN these settings will cause major problems, but I’ve yet to come even close.
After reading that blog post and doing a bit more research, I’ve also added the -server option, though it’s not clear whether that’ll actually have any benefit. I’ll report back once I’ve had some time using it. More info here here and here.
It seems that Windows users may also benefit from -Dsun.awt.keepWorkingSetOnMinimize=true which is supposed to prevent IntelliJ from becoming unresponsive when losing focus. Forum post explanation here
Adding on Mac
The options are defined in the Info.plist file which is part of the .app bundle (for example, mine is in /Applications/IntelliJ IDEA 9.0.3 CE.app/Contents/Info.plist).
Find the VMOptions key and add the options to the value, like so:
<key>VMOptions</key>
<string>-Xms1024m -Xmx1024m -XX:MaxPermSize=1024m -ea -Xverify:none -server -XX:+UseCompressedOOPS -Xbootclasspath/a:../lib/boot.jar</string>
I don’t have a Windows machine handy, so someone else will have to come up with those instructions.
