Stack VS Heap


Stack

1. Stack is memory in computer which is used to store temporary information. For eg. variables are stored on stack.
2.Information after the method is done with its execution.
3. Stack is non- shared memory which means that data of a particular thread stored on stack can be seen only by the owner of data.

Which variables are stored where?


There are mainly three types of variables:

 1.Instance variables.
 2.Static variables.
 3.Primitive or local variables.


Storage:

Instance variables : Objects and its instance variable are stored in heap (young generation area).

Primitive or local variables : Stack

Methods :Stack

Reference of objects  : on stack

Static variable and static methods: on Permanent Generation area of heap

Stack VS Heap

Heap

  1. Heap is mainly used to store objects.
 2. Its a shared memory.
 3. Both class instances and arrays are stored on heap.
 4. This area of memory is shared by all threads. 


Stack VS Heap

For providing more information on topic or questions please comment below .

Post a Comment