View RSS Feed

Core Java

Java stack and heap memory

Rate this Entry
by , 01-08-2012 at 11:43 AM (5528 Views)
Heap is used to store new objects created by Java. Stack is used to store primitive data types like int and double when they are declared locally. These primitive data types are stored on heap when they are declared globally. Whenever a Java method is called, all the local variables are pushed to stack and its pointer is decremented after completion of that method call. In a multithreaded application only one heap is used and each thread contains its own stack. So do not declare your data globally that will be placed on heap and updated by multiple threads to avoid sybchronization issues. Heap is not thread safe as compare to stack which is thread safe.

Name:  58.JPG
Views: 4244
Size:  35.9 KB

Java stack and heap memory

Submit "Java stack and heap memory" to Facebook Submit "Java stack and heap memory" to Digg Submit "Java stack and heap memory" to del.icio.us Submit "Java stack and heap memory" to StumbleUpon Submit "Java stack and heap memory" to Google

Categories
Stack

Comments