[Java] Difference between Stack Overflow Error and Out Of Memory Error

A note of what I researched when studying Java Silver.

What is the difference between StackOverflowError and OutOfMemoryError?

What is StackOverflowError?

Class StackOverflowError Error caused by running out of memory in ** stack area **

[Example of situations that occur] Make a ** recursive call ** within a method

[What is the stack area] A memory area that stores ** local variable and method information **. As the name suggests, it has a stack-like data structure (last-in, first-out method).

If you keep calling your own method in the method, the method information will accumulate in the stack area and you will get a flat tire. Then, the JVM (Java Virtual Machine) detects that the stack area is insufficient and raises a StackOverflowError.

What is OutOfMemoryError?

Class OutOfMemoryError

Thrown when the Java Virtual Machine is unable to allocate an object due to lack of memory and the garbage collector cannot allocate any more available memory.

Error caused by running out of memory in ** heap area **

[Example of situations that occur] ** Infinite loop ** is happening (Reference: Understanding OutOfMemoryError Exceptions)

[What is a heap area] An area for storing ** instance ** information.

Summary

StackOverflowError occurs when the memory (stack) allocated to the JVM is full. If the JVM fails to allocate memory, an OutOfMemoryError will occur.

References

-What is a heap area? Explain the difference from the stack area and the specific management method!

・ [What is the stack area](http://www.kab-studio.biz/Programing/JavaA2Z/Word/00000987.html#:~:text=%E3%83%A1%E3%83%A2%E3% 83% AA% E4% B8% 8A% E3% 81% AE% E3% 80% 81% E3% 83% AD% E3% 83% BC% E3% 82% AB% E3% 83% AB% E5% A4% 89% E6% 95% B0,% E6% A0% BC% E7% B4% 8D% E3% 81% 99% E3% 82% 8B% E9% A0% 98% E5% 9F% 9F% E3% 81% AE % E3% 81% 93% E3% 81% A8% E3% 80% 82 & text = JVM% E3% 81% 8C% E4% BD% BF% E7% 94% A8% E3% 81% 99% E3% 82% 8B % E3% 83% A1% E3% 83% A2% E3% 83% AA,% E7% 8A% B6% E3% 81% AB% E6% A0% BC% E7% B4% 8D% E3% 81% 95% E3% 82% 8C% E3% 82% 8B% E3% 80% 82)

Recommended Posts

[Java] Difference between Stack Overflow Error and Out Of Memory Error
[Java] Difference between == and equals
[Java] Difference between Hashmap and HashTable
[Java] Difference between assignment of basic type variable and assignment of reference type variable
[Java] Difference between array and ArrayList
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
Difference between pop () and peek () in stack
[For beginners] Difference between Java and Kotlin
Difference between isEmpty and isBlank of StringUtils
Difference between addPanel and presentModally of FloatingPanel
[Java] Difference between Intstream range and rangeClosed
Difference between int and Integer in Java
[Java] Understand the difference between List and Set
Difference between next () and nextLine () in Java Scanner
[Java] Classification memo of compilation error and run-time error
Difference between member and collection of rails routes.rb
[Java] Difference between "final variable" and "immutable object"
Difference between vh and%
Difference between i ++ and ++ i
[Java] Difference between static final and final in member variables
[JAVA] What is the difference between interface and abstract? ?? ??
What is the difference between Java EE and Jakarta EE?
[Java beginner] Difference between length and length () ~ I don't know ~
Difference between product and variant
[Docker-compose] Difference between env_file and environment. Priority of environment variable application
Difference between redirect_to and render
[Java] Stack area and static area
Rails: Difference between resources and resources
Difference between Java and JavaScript (how to find the average)
Difference between puts and print
Difference between redirect_to and render
Difference between CUI and GUI
Difference between variables and instance variables
Difference between mockito-core and mockito-all
[Ruby] About the difference between 2 dots and 3 dots of range object.
Difference between class and instance
Difference between bundle and bundle install
[Java] Check the difference between orElse and orElseGet with IntStream
Difference between ArrayList and LinkedList
Difference between render and redirect_to
Difference between List and ArrayList
java Generics T and? Difference
Advantages and disadvantages of Java
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
Difference between render and redirect_to
Summary of java error processing
Is short-circuit evaluation really fast? Difference between && and & in Java
Output the difference between each field of two objects in Java
After switching between Java 8 and 11 versions, an error occurs in confirmation
Difference between byCharWrapping and byWordWrapping of UI Label in Japanese display
[Java] What is the difference between form, entity and dto? [Bean]
[Ruby] Difference between get and post
Difference between instance method and class method
Difference between interface and abstract class
Difference between == operator and equals method
Differences between "beginner" Java and Kotlin
About fastqc of Biocontainers and Java