Does GC collect garbage from Metaspace?

I always thought that the garbage collector only cleans up the heap, and now I think so.

In java 8, permGen was removed and replaced with Metaspace.

And As I understand it Metaspace is garbage collection ( stack overflow )

Who collects the garbage from Metaspace?

+3


source to share


1 answer


I think your confusion stems from the colloquial term "garbage collection", which is widely used but does not describe what happens in a controlled environment.

Memory management is a complex process that has been simplified:

  • Identifying objects that are garbage, which is actually the process of determining which objects are reachable (read: not garbage) and consider anything that does not occur to be garbage
  • Setting object references for reference queues and / or trigger completion as needed
  • Recovering memory previously occupied by garbage, which can also be the other way around: sometimes live objects are moved to another memory space instead of

So, for a memory space not made up of Java objects, the first two points usually don't make much sense, which is what you think your question is about. The algorithms that process the first two points usually process the Java heap (defined as a space containing regular instances of Java objects and similar structured data).



The statement you linked when you said "Metaspace is GCed" seems to be mainly about the third point. That the memory in Metaspace can be fixed if more is not needed. This does not mean that it requires traversing live links in the metapass or anything similar. Obviously, the class metadata was deprecated when its associated Class

and ClassLoader

became inaccessible, which are regular (well, almost) objects living on the Java heap.

So when the size of Metaspace reaches the limit, garbage collection will be triggered, but regarding the first two bullets above, it will not process Metaspace since it is not Metaspace which can tell you if it has become Class

unused. This will be normal garbage collection, but it will be "Full GC" or whatever term is currently used by the GC algorithm for a mode that includes garbage collection on a memory segment (aka "generation") that contains classes and classloaders ...

Once the heap instances have been collected Class

and ClassLoader

their associated metapass data can be corrected during cleanup as well.

+3


source







All Articles