Java objects reside in an area called the heap. The heap is created when the JVM starts up and may increase or decrease in size while the application runs. When the heap becomes full, garbage is collected. During the garbage collection objects that are no longer used are cleared, thus making space for new objects.
The heap is sometimes divided into two areas (or generations) called the nursery (or young space) and the old space. The nursery is a part of the heap reserved for allocation of new objects. When the nursery becomes full, garbage is collected by running a special young collection, where all objects that have lived long enough in the nursery are promoted(moved) to the old space, thus freeing up the nursery for more object allocation. When the old space becomes full garbage is collected there, a process called an old collection.
The reasoning behind a nursery is that most objects are temporary and short lived. A young collection is designed to be swift at finding newly allocated objects that are still alive and moving them away from the nursery. Typically, a young collection frees a given amount of memory much faster than an old collection or a garbage collection of a single-generational heap (a heap without a nursery).
The heap is the run-time data
area from which memory for all class instances and arrays is allocated.
The heap may be of a fixed
size or may be expanded as required by the computation and may be contracted if
a larger heap becomes unnecessary.
if a computation requires more
heap than can be made available by the automatic storage management system, the
Java Virtual Machine throws an
OutOfMemoryError
.- heavy Java process, insufficient Heap size will cause the
popular
java.lang.OutOfMemoryError:
Change the size of Heap.
-Xms<size> - Set initial Java heap
size
-Xmx<size> - Set maximum Java heap
size
No comments:
Post a Comment