Java Garbage Collection – Does JVM Clean Entire HotSpot Memory or Just Java Heap?

garbage-collectionheapjavajvm

I know that the JVM has some JVM HotSpot memory which is further divided into three areas:

  • Java Heap
  • Permanent Generation Space
  • Native Heap (C-Heap)

I know that Java has automatic garbage collection mechanism for Heap Memory.

So, I want to confirm that in my last statement Heap refers to both Java Heap and Native Heap (C-Heap) or just Java Heap.

Also, what about Permanent Generation Space? Is it also considered as some kind of Heap or what?

Best Answer

The GC will collect both the Java Heap and the permgen, but not the native heap. The native heap is manually managed by whatever C code owns it. The permgen, on the other hand, is managed by the JVM garbage collector (though not necessarily as efficiently as the rest of the heap, as certain GC algorithms will only compact the permgen when absolutely necessary).