What are Minor, Major and Full garbage collection in JVM in java


In this core java tutorial we will learn What are Minor, Major and Full garbage collection in JVM in java.


Contents of page >
  • A) JVM Heap memory (Hotspot heap structure) with diagram in java >
  • B) JVM Heap memory (Hotspot heap structure)  in java consists of following elements>
  • C) What are Minor, Major and Full garbage collection in JVM Heap memory in java >
  1. Young Generation (Minor garbage collection occurs in Young Generation)
  2. Old Generation (tenured generation) - (Major garbage collection occurs in Old Generation)
  3. Permanent Generation or (Permgen) - (full garbage collection occurs in permanent generation in java).


A) JVM Heap memory (Hotspot heap structure) with diagram in java >
Before learning about Minor, Major and Full garbage collection in java we must know about JVM Heap memory (Hotspot heap structure).

B) JVM Heap memory (Hotspot heap structure)  in java consists of following elements>
  1. Young Generation
    • 1a) Eden,
    • 1b) S0 (Survivor space 0)
    • 1c) S1 (Survivor space 1)
  2. Old Generation (Tenured)
  3. Permanent Generation.

C) What are Minor, Major and Full garbage collection in JVM Heap memory in java >

  1. Young Generation (Minor garbage collection occurs in Young Generation)

New objects are allocated in Young generation.

Young Generation is further divided into three parts Eden, S0 (Survivor space 0) and S1 (Survivor space 1).

When minor garbage collection?
When the young generation fills up, this causes a minor garbage collection.
All the unreferenced (dead) objects are cleaned up from young generation.

When objects are moved from young to old generation in JVM heap?
Some of the objects which aren't cleaned up survive in young generation and gets aged.  Eventually such objects are moved from young to old generation.

What is Stop the World Event?
Minor garbage collections are called Stop the World events.
All the non-daemon threads running in application are stopped during minor garbage collections (i.e. the application stops for while).
Daemon threads performs minor garbage collection. (Daemon threads are low priority threads which runs intermittently in background for doing garbage collection).


  1. Old Generation (tenured generation) - (Major garbage collection occurs in Old Generation)
The Old Generation is used for storing the long surviving aged objects (Some of the objects which aren't cleaned up survive in young generation and gets aged.  Eventually such objects are moved from young to old generation).

At what time (or what age) objects are moved from young to old generation in JVM heap?
There is some threshold set for young generation object and when that age is met, the object gets moved to the old generation during garbage collection in java.

What is major garbage collection in java?
When the old generation fills up, this causes a major garbage collection. Objects are cleaned up from old generation.
Major collection is much slower than minor garbage collection in jvm heap because it involves all live objects.

Major garbage collection are Stop the World Event in java?
Major garbage collections are also called Stop the World events.
All the non-daemon threads running in application are stopped during major garbage collections.
Daemon threads performs major garbage collection.

Major garbage collections in responsive applications in java?
Major garbage collections should be minimized for responsive applications because applications must not be stopped for long.

Optimizing Major garbage collections in responsive applications in java?
Selection of appropriate garbage collector for the old generation space affects the length of the “Stop the World” event for a major garbage collection.

  1. Permanent Generation or (Permgen) - (full garbage collection occurs in permanent generation in java).

Permanent generation Space contains metadata required by JVM to describe the classes and methods used in the application.

The permanent generation space is populated at runtime by JVM based on classes in use in the application.

The permanent generation space also contains Java SE library classes and methods in java.

JVM garbage collects those classes when classes are no longer required and space may be needed for other classes in java.




Summary -

I am highlighting all the summary portion to keep it separate from whole tutorial. Please refer above for complete detail.

JVM Heap memory (Hotspot heap structure)  in java consists of following elements>
  1. Young Generation
    • 1a) Eden,
    • 1b) S0 (Survivor space 0)
    • 1c) S1 (Survivor space 1)
  2. Old Generation (Tenured)
  3. Permanent Generation.

What are Minor, Major and Full garbage collection in JVM Heap memory in java >

  1. Young Generation (Minor garbage collection occurs in Young Generation)

New objects are allocated in Young generation.

Minor garbage collection occurs in Young Generation.

When minor garbage collection?
When the young generation fills up, this causes a minor garbage collection.
All the unreferenced (dead) objects are cleaned up from young generation.

  1. Old Generation (tenured generation) - (Major garbage collection occurs in Old Generation)
The Old Generation is used for storing the long surviving aged objects.

Major garbage collection occurs in Old Generation.

When the old generation fills up, this causes a major garbage collection. Objects are cleaned up from old generation.

  1. Permanent Generation or (Permgen) - (full garbage collection occurs in permanent generation in java).

Permanent generation Space contains metadata required by JVM to describe the classes and methods used in the application.

The permanent generation is included in a full garbage collection in java.

So in this core java tutorial we learned What are Minor, Major and Full garbage collection in JVM in java.


Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>



JVM in detail - Garbage collection & heap structure >

>JVM Heap memory (Hotspot heap structure) with diagram in java


Young, Old (tenured) and Permanent Generation >

>What are Young, Old (tenured) and Permanent Generation in JVM in java


Minor, Major and Full garbage collection >

>What are Minor, Major and Full garbage collection in JVM in java



Important VM parameters >

>Most important and frequently used VM (JVM) PARAMETERS with examples in JVM Heap memory in java

>What are -XX:NewSize and -XX:MaxNewSize JVM parameters in java


eEdit
Must read for you :