3. Difference between Stack and Heap In java
Stack
|
Heap
|
1. Stack memory is used to store Local variables and function call.
|
1. Heap memory is used to store objects in Java.
|
2. If there is no memory left in the stack for storing
function call or local variable, JVM will throw java.lang.StackOverFlowError.
|
2. if
there is no more heap space for creating an object, JVM will throw java.lang.OutOfMemoryError.
|
3. size of stack memory is a lot lesser than the size of heap memory .
|
3. size of Heap memory is a bigger than the size of stack memory.
|
4. Variables stored in stacks are only visible to the owner
Thread. In other words, stack memory is kind of private memory of
Java Threads.
|
4. objects created in
the heap are visible to all thread. and heap memory is
shared among all threads.
|
No comments:
Post a Comment