Refreshing our memory by managing memory in Java... Let's have a quick review on this.
1. Java Heap Size
The place where objects get stored created by our Java application. It's where Garbage Collection takes place. For a heavy Java process, insufficient Heap size will cause the popular java.lang.OutOfMemoryError: Java heap space
.
-Xms<size> - Set initial Java heap size
-Xmx<size> - Set maximum Java heap size
$ java -Xms512m -Xmx1024m JavaApp
2 . Perm Gen Size
The place where we store our loaded class definition and metadata. If a large code-base project is loaded, the insufficient Perm Gen size will cause the popular Java.Lang.OutOfMemoryError: PermGen
.
-XX:PermSize<size> - Set initial PermGen Size.
-XX:MaxPermSize<size> - Set the maximum PermGen Size.
$ java -XX:PermSize=64m -XX:MaxPermSize=128m JavaApp
3. Java Stack Size
It's the size of a Java thread. If a project has a lot of threads processing, try to reduce this stack size to avoid running out of memory. -Xss = set java thread stack size
$ java -Xss512k JavaApp