Java Interview Reference Guide – Heap

Heap Memory:

Each time an object is created in Java it goes into the specific memory known as Heap. The member variables of class store in Stack (i.e. Last In First Out) and member variables will store in Heap.

Allocating of Memory in Stack is in run-time when method called it will push to stack and stack pointer increment, stack decremented if method got over.

Heap memory is single memory shared by all thread of JVM whereas each threat contains it own copy of stack memory that’s why Heap is not thread safe and that’s reason we need to handle concurrency issue for Heap memory.

Threads can be executing same method multiple times keeping with its own local variables in his stack memory.

JAVA VM

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s