Java memory

Java has 3 types of memory

heap non-heap native

Heap memory
runtime data area from which memory for all class instances and arrays is allocated.

heap memory error example:

java.lang.OutOfMemoryError: Java heap space

Loads of info on heap here; http://www.testing-software.org/tag/heap

Total Heap
Since collections occur when generations fill up, throughput is inversely proportional to the amount of memory available. Total available memory is the most important factor affecting garbage collection performance.

By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range. This target range is set as a percentage by the parameters -XX:MinHeapFreeRatio= and -XX:MaxHeapFreeRatio=, and the total size is bounded below by -Xms and above by -Xmx. The default parameters for the 32-bit Solaris Operating System (SPARC Platform Edition) are shown in this table:

Eden Space (heap)
Initially, the Virtual Machine assigns all (most?) objects to the Eden Space.

Garbage collection occurs in each generation when it fills up (uses up its allotted memory); the VM performs a partial garbage collection (minor collection) on that memory pool to reclaim memory used by dead objects. The VM moves (promotes) any remaining objects from the Eden Space to one of the Survivor Spaces

Survivor space (heap)
The VM moves objects that live long enough in the Survivor Spaces to the Tenured Space in the old generation.

Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.

Tenured space (heap)
Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.

When the tenured generation fills up, there is a full GC (major collection) that is often much slower because it involves all live objects.

Non-heap memory
method area and memory required for the internal processing of the JVM, or optimization of the JVM

java.lang.OutOfMemoryError: PermGen space

Permanent Generation
(non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.

Code Cache
(non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.

permanent generation
The permanent generation holds all the reflective data of the virtual machine itself, such as class and method objects.

Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.

Code Cache
Code Cache (non-heap): The HotSpot Java Virtual Machine also includes a code cache, containing memory that is used for compilation and storage of native code

native memory
the virtual memory managed by the operating system

java.lang.OutOfMemoryError: request bytes for. Out of swap space?