IDE

IntelliJ Increase Memory Settings

In this article we are going to provide some guidelines on how to increase memory heap on IntelliJ IDEA and on how to configure the VM options. For our example we are using IntelliJ IDEA Community Edition version 14.1.2.

1. Configuring IntelliJ IDEA VM options

The default VM options for IntelliJ IDEA may be not optimal when your project contains a quite large number of classes (e.g more than 15000) and developers often try to change the default options to minimize IntelliJ IDEA hangtime. But sometimes the changes make things even worse. So, how to configure IntelliJ IDEA VM options optimally? That’s not so easy question to answer, since the configuration strongly depends on the project being developed. Therefore, we can recommend some settings that developers use and explain the general memory policy.

1.1 Optimal VM options

-Xms = 128m
-Xmx = 256m

Please note that very big Xmx and Xms values are not optimal. In this case, the garbage collector has to deal with a large part of memory at a time and causes considerable hang-ups. On the other hand, too small values can lead to the OutOfMemory exception. The specified values provide enough memory and at the same time the garbage collector works often but rather fast.

-XX:MaxPermSize=92m

This is a default value, and in most cases you don’t need to change it. You may increase it only if you get “OutOfMemoryError” in “PermGen space”.

-server

Some people find IntelliJ IDEA more responsive with this option. But it is not guaranteed. We don’t recommend to use the following options at all, since they are not very stable:

-XX:+UseParallelGC

If you are on a multi-core machine, enabling parallel garbage collection can help (reduces gc pauses), although there are stability issues with this option.

-XX:+UseAdaptiveSizePolicy
-XX:-UseConcMarkSweepGC

1.2 Changing IntelliJ IDEA properties

IntelliJ IDEA makes it possible to change *.vmoptions and idea.properties files without editing them in the IntelliJ IDEA installation folder. In IntelliJ IDEA 14.1.2 these files are located under C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.2\bin installation directory. You should edit a copy of these files. The reason is that app bundle is signed and you should not modify any files inside the bundle; therefore, you need to make a copy in IDE preferences folder, which you will modify.

1.2.1 Managing *.vmoptions file

For Mac OS X systems

Since version 12.0.0: The file /Applications/IntelliJ Idea XX.app/bin/idea.vmoptions or /Applications/IntelliJ Idea CE XX.app/bin/idea.vmoptions should be copied to ~/Library/Preferences/IntelliJIdeaXX/idea.vmoptions or ~/Library/Preferences/IdeaICXX/idea.vmoptions

Since version 14.0.0: The file /Applications/IntelliJ Idea XX.app/Contents/bin/idea.vmoptions or /Applications/IntelliJ Idea CE XX.app/Contents/bin/idea.vmoptions should be copied to ~/Library/Preferences/IntelliJIdeaXX/idea.vmoptions or ~/Library/Preferences/IdeaICXX/idea.vmoptions

For the older versions, the settings are stored in /Applications/IntelliJ IDEA .app/Contents/Info.plist.

For *NIX and Windows systems

To avoid editing files in the IntelliJ IDEA installation folder, one should:

Do one of the following:

  • Go to Run->Edit Configurations… and set the VM options field with the desired values:

    VM options configuration
    VM options configuration
  • Copy the existing file from the IntelliJ IDEA installation folder somewhere and save the path to this location in the environment variable IDEA_VM_OPTIONS. If IDEA_VM_OPTIONS environment variable is defined, or the *.vmoptions file exists, then this file is used instead of the file located in the IntelliJ IDEA installation folder.
  • Copy the existing file /bin/idea$BITS.vmoptions from the IntelliJ IDEA installation folder into the location under user home: For Windows: %USERPROFILE%\.IntelliJIdeaXX\idea%BITS%.exe.vmoptions or %USERPROFILE%\.IdeaICXX\idea%BITS%.exe.vmoptions. The value of the variable BITS depends in the JVM used to run IntelliJ IDEA:
    1. For 32-bit JVM it is empty.
    2. For 64-bit JVM it is 64.
  • Edit this file in the new location.

2. Increasing memory heap of the build process

To increase a memory heap:

  • Open the Build->Compiler Settings dialog box:

    Build process heap size
    Build process heap size
  • In the Build process heap size field, type the required amount of memory in MB.

    Please note the following:The memory heap of the build process is independent of IntelliJ IDEA memory heap, and is released after the build process is complete. The IntelliJ IDEA memory heap is indicated on the bottom right of the IDE and specifically on the status bar which shows the current IDE state and lets you carry out certain environment maintenance tasks. Visibility of this section in the Status bar is defined by the Show memory indicator check box in the Appearance page of the Settings dialog as depicted in the image below. It is not shown by default.

    Memory Indicator
    Memory Indicator
  • Upon clicking the indicator, the garbage collector runs.

3. Code example

In this section we are going to present a code example in which we use the default settings (-Xms64m, -Xmx128m) and leads to an OutOfMemoryException and the same example running successfully after setting VM options in Run Configurations with -Xmx256m.

public class MaxHeapSizeViolated {

    static final int SIZE=30*1024*1024;
    public static void main(String[] a) {
        int[] i = new int[SIZE];
    }
}

The array of integers allocated with the above code example leads to an OutOfMemoryError when using the default -Xmx128m vm option:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at MaxHeapSizeViolated.main(MaxHeapSizeViolated.java:8)

After setting the -Xmx256m vm option in Run configurations the above code does not lead to an OutOfMemory exception.

4. Conclusion

In this example we tried to demonstrate the various ways of increasing / modifying memory settings inside IntelliJ IDEA and it looks like that even some simple changes in the VM options can significantly improve performance of our work. The purpose is to use the IDE in order to run different applications with regard to memory requirements and for this reason the developer should be able to find a balance between performance gain and memory consumption.

Nassos Hasiotis

Nassos has graduated from Computer Engineering and Informatics Department in the University of Patras. He also holds a Master degree in Communication and Network Systems from University of Athens. He has a 10-year work experience as a Java and C++ developer in the Telecommunication and IT industry participating in various projects. He currently works as a senior software developer in the IT sector where he is mainly involved with projects for the EU requiring extensive java skills.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button