The difference between Java Stackoverflowerror and OutOfMemoryError

Source: Internet
Author: User

1, StackOverflow:

Whenever a Java program launches a new thread, the Java virtual Opportunity allocates a stack for him, and the Java stack keeps the thread running in frames, and when the thread calls a method, the JVM presses a new stack frame into the thread's stack, and the stack frame exists as long as the method does not return.
If a method has too many nested call hierarchies (such as recursive calls), as the number of frames in the Java stack increases, the sum of all the stack frames in the stack of the thread will eventually be greater than the value set by the-XSS, resulting in a raw stackoverflowerror overflow exception.

2, OutOfMemory:

2.1, Stack memory overflow

When a Java program launches a new thread, there is not enough space to allocate the Java stack for the thread, the size of the Java stack is determined by the-XSS setting, and the JVM throws a OutOfMemoryError exception.

2.2. Heap Memory Overflow

The Java heap is used to hold an instance of an object, and throws an OutOfMemoryError exception when it is necessary to allocate memory for an instance of an object, while the heap occupies the maximum value set (via-xmx) to set the maximum value.

2.3. Method Area Memory Overflow

The method area is used to store information about Java classes, such as class names, access modifiers, Chang, field descriptions, method descriptions, and so on. When the class loader loads the class file into memory, the JVM extracts the information from the classes and puts the class information in the method area.
When these class information needs to be stored and the memory footprint of the method area has reached its maximum (via-xx:maxpermsize), the basic idea is that the OutOfMemoryError exception will be thrown to the test of this situation, and the fundamental thought is that the runtime generates a large number of classes to fill the method area until it overflows. There are a lot of dynamic classes that need to be run with Cglib directly to manipulate bytecode.

Transferred from: http://blog.csdn.net/chenchaofuck1/article/details/51144223

Java Stackoverflowerror and OutOfMemoryError differences (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.