Optimize JVM memory to solve outofmemoryerror
From the VM specification, we can see several exceptions.
Java. Lang. stackoverflowerror :( very few)
Java. Lang. outofmemoryerror: heap space (common)
Java. Lang. outofmemoryerror: permgen space (frequently seen)
The following are the most common examples:
- Java. Lang. outofmemoryerror
Permgen space is a common exception. It refers to the exception overflow in the perm memory area of JVM. Due to the default situation of JVM, perm is 64 MB by default, while manyProgramA large amount of perm memory is required, especially when a framework like spring is used. Because dynamic generation classes are required, these classes cannot be automatically released by GC, resulting in outofmemoryerror: permgen space is abnormal. The solution is simple. Increase the JVM
-XX: maxpermsizeTo solve this problem.
- Java. Lang. outofmemoryerror
Heap space or other outofmemoryerror. This exception is actually an exception that keeps up with the preceding exception, but the solution is different, so it is written separately. The above exception is caused by the memory difference in the JVM perm zone (JVM memory is divided into three types: young, old, and Perm ). This exception occurs because the JVM heap memory or the overall score is less. The solution is to change
-XMS-xmxThe startup parameter is usually doubled. XMS manages the Minimum Memory volume during startup, and xmx manages the maximum JVM memory volume.
- Java. Lang. stackoverflowerror
Honestly, I have never met this exception, but the JVM specification mentioned that there are several situations that may throw this exception. One is that when the thread in stacks exceeds the permitted value, the other is when the native method requires a larger memory and exceeds the memory allowed by the native method. According to Sun's documentation-XX: thread stacksize = 512.