One , Stack overflow (StackOverflowError)

The stack is thread private , His life cycle is the same as threads , Each method creates a stack frame when it is executed , Used to store the local variable table , Operands stack , dynamic link , Method exit light information . The local variable table also contains the basic data types , Object reference type ( Local variable table compiler complete , It does not change during operation )

So we can understand that stack overflow is that the stack frame created by method execution exceeds the depth of stack . Most likely, then, is that recursive method calls produce this result .
public class JvmTest { private int i = 0; public void a(){
System.out.println(i++); a(); } public static void main(String[] args) {
JvmTest j = new JvmTest(); j.a(); } }
Output results :

How to solve this problem :

We need to use parameters -Xss To adjust JVM Stack size

The effect is as follows

But you need to be aware of the risks of recursive programs .

Two , Heap overflow (OutOfMemoryError:java heap space)

heap space Represents heap space , Objects are mainly stored in the heap . If it continues new Object causes space overflow in the heap
public class JvmTest { public static void main(String[] args) { List<String>
aList = new ArrayList<String>(); try{ while(true){ aList.add("asdasdasdas"); }
}catch(Throwable e){ System.out.println(aList.size()); e.printStackTrace(); } }
Abnormal information :

It can be done through  -Xmx4096M Adjust the total size of the heap

Three , Permanent generation overflow (OutOfMemoryError: PermGen space)

because JDK7,8 Remove permanent belt , So the above code is in JDK1.6 There will be a permanent overflow in the case of .


©2019-2020 Toolsou All rights reserved,
Python Garbage collection and memory leak hive Summary of processing methods for a large number of small files The difference between memory overflow and memory leak , Causes and Solutions Create data mysql Library process You don't know ——HarmonyOS stay Vue Use in Web WorkerSparkSQL Achieve partition overlay write msf Generate Trojan horse attack android mobile phone Linux Page replacement algorithm C Language implementation Django Personal blog building tutorial --- Time classified archiving