Thursday, March 06, 2014

Memory

Memory (Stack vs. Heap)

Java stores primitives on the stack, objects on the heap.

Pointers to objects are stored on the stack.

Elements stored on the heap are FIFO (first in first out).

When the stack memory is used up Java throws  java.lang.StackOverFlowError

When the heap memory is used up Java throws java.lang.OutOfMemoryError
 
Recursion can fill up the stack

Variables on the stack are available only to the thread that owns them.


Objects on the heap are visible to all threads.

http://gribblelab.org/CBootcamp/7_Memory_Stack_vs_Heap.html 

http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap

http://www.vogella.com/tutorials/JavaPerformance/article.html