Sr. No. | Key | Stack | Heap Memory |
---|---|---|---|
1 | Basic | Stack memory is used to store items which have a very short life like local variables, a reference variable of objects | Heap memory is allocated to store objects and JRE classes. |
2 | Ordering | The stack is always reserved in a LIFO (last in first out) order | Heap memory is dynamic allocation there is no fixed pattern for allocating and deallocating blocks in memory |
3 | Size | We can increase stack memory size by using JVM parameter -XSS | We can increase or decrease heap memory size by using JVM option -Xms and -Xmx |
4 | Visibility | Variables are visible to only to owner thread | It is visible to all threads |
5 | Exception | JVM will throw java.lang.StackOverFlowError | JVM will throw java.lang.OutOfMemoryError |
写在最后
欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment