·
Each thread has its own stack when ever thread
initialize then that thread gowns to memory of stack
·
If there is no
memory left in stack for storing function call or local variable, JVM will
throw
·
Exceptions of stack
java.lang.StackOverFlowError, while if there is no more heap space for creating
object, JVM will
throw
java.lang.OutOfMemoryError:
Java Heap Space. Read more about how to deal
with c:- java.lang.OutOfMemoryError
A) If you
are using Recursion, on which method calls itself,
You can quickly fill up stack memory. Another difference between stack and heap
is that size of stack memory is lot lesser than size of heap memory in Java.
B)
Variables stored in stacks are only visible to the owner Thread, while objects
created in heap are visible to all thread. In other words stack memory is kind
of private memory of Java Threads, while heap memory is shared among all
threads
·
Heap and stack both store in RAM
· Can an object be stored on the stack instead of the heap?
·
Yes, an object can be stored on the
stack. If you create an object inside a function without using the “new”
operator then this will create and store the object on the stack, and not on
the heap
How long does memory on the stack last versus memory on the heap?
Once a function call runs to completion, any data on the stack created specifically for that function call will automatically be deleted. Any data on the heap will remain there until it’s manually deleted by the programmer.
·
We cannot increase the size of stack but we can
increase the size of heap
·
By the help of commands
·
Xss> increase to stack
·
Xms>
·
Xmx> increase to heap memory.
Both of them initialized memory at
dynamic time mostly it can static also
Which is faster – the stack or the heap? And why?
The stack is much faster than the heap. This is because of the way that memory is allocated on the stack. Allocating memory on the stack is as simple as moving the stack pointer up.How is memory deallocated on the stack and heap?
Data on the stack is automatically
deal located when variables go out of scope.
free, delete, or delete[ ].
Other languages like Java and .NET use garbage collection to automatically
delete memory from the heap, without the programmer having to do anything..
No comments:
Post a Comment