Why does Intellij not release memory after closing a project?

Following up on @PeterGromov's answer it seems that is were difficult to obtain the memory back. In addition @KevinKrumwiede mentioned the XX:MaxHeapFreeRatio which appears to be an avenue.

Here are a couple of those ideas taken bit farther from Does GC release back memory to OS?

The HotSpot JVM does release memory back to the OS, but does so reluctantly.

You can make it more aggressive by setting -XX:GCTimeRatio=19 -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=30 which will allow it to spend more CPU time on collecting and constrain the amount of allocated-but-unused heap memory after a GC cycle.

Additionally with Java 9 -XX:-ShrinkHeapInSteps option can be be used to apply the shrinking caused by the previous two options more aggressively. Relevant OpenJDK bug.

Do note that shrinking ability and behavior depends on the chosen garbage collector. For example G1 only gained the ability to yield back unused chunks in the middle of the heap with jdk8u20.

So if heap shrinking is needed it should be tested for a particular JVM version and GC configuration.

and from How to free memory in Java?

To extend upon the answer and comment by Yiannis Xanthopoulos and Hot Licks (sorry, I cannot comment yet!), you can set VM options like this example:

-XX:+UseG1GC -XX:MinHeapFreeRatio=15 -XX:MaxHeapFreeRatio=30 In my jdk 7 this will then release unused VM memory if more than 30% of the heap becomes free after GC when the VM is idle. You will probably need to tune these parameters.

While I didn't see it emphasized in the link below, note that some garbage collectors may not obey these parameters and by default java may pick one of these for you, should you happen to have more than one core (hence the UseG1GC argument above).

I am going to add the -XX:MaxHeapFreeRatio to IJ and report back if it were to help.

Our application presently only runs on Java7 so the first approach above is not yet viable - but there is hope since our app is moving to jdk8 soon.