
Typically, some fraction of the surviving objects from the young generation are moved to the old generation during each minor collection.
#Jprofiler find garbage collector algorithm full#
The costs of such collections are, to the first order, proportional to the number of live objects being collected a young generation full of dead objects is collected very quickly. When the young generation fills up, it causes a minor collection in which only the young generation is collected garbage in other generations isn't reclaimed. The vast majority of objects are allocated in a pool dedicated to young objects (the young generation), and most objects die there. Garbage collection occurs in each generation when the generation fills up.

To optimize for this scenario, memory is managed in generations (memory pools holding objects of different ages). For example, iterator objects are often only alive for the duration of a single loop. The sharp peak at the left represents objects that can be reclaimed (in other words, have "died") shortly after being allocated. The byte count on the y-axis is the total bytes in objects with the corresponding lifetime. The x-axis shows object lifetimes measured in bytes allocated. The blue area in Figure 3-1 is a typical distribution for the lifetimes of objects. The most important of these observed properties is the weak generational hypothesis, which states that most objects survive for only a short period of time.

While naive garbage collection examines every live object in the heap every time, generational collection exploits several empirically observed properties of most applications to minimize the work required to reclaim unused (garbage) objects. The Java HotSpot VM incorporates a number of different garbage collection algorithms that all use a technique called generational collection. The time this approach takes is proportional to the number of live objects, which is prohibitive for large applications maintaining lots of live data. Any leftover objects are considered garbage. An object is considered garbage and its memory can be reused by the VM when it can no longer be reached from any reference of any other live object in the running program.Ī theoretical, most straightforward garbage collection algorithm iterates over every reachable object every time it runs.
