Question

I was reading this article and it says

Permanent generation of Heap or Perm Area of Heap is somewhat special and it is used to store Meta data related to classes and method in JVM, it also hosts String pool provided by JVM as discussed in my string tutorial why String is immutable in Java. There are many opinions around whether garbage collection in Java happens in perm area of java heap or not, as per my knowledge this is something which is JVM dependent and happens at least in Sun's implementation of JVM. You can also try this by just creating millions of String and watching for Garbage collection or OutOfMemoryError

So I have one question:

Does garbage collection happens in Perm area of heap.if not then how static variables or methods and string literal pool gets garbage collected?

Était-ce utile?

La solution

Grabage collection do happen in permgen (Jvm implementation based). I wrote a answer to SO question how to deliberately fill perm gen. JVM loads metadata that is classes etc in permgen area. If for some reason JVM is running low on permgen it can decide to unload classes that have no references anywhere. But when that GC runs or if run at all may very well differ from JVM to JVM implementation.

Unloading classes to create room is the last ditch effort by a jvm before it throws "Outof memory: permgen space"

Please take a look at this Question SO Link this might be helpful Basically this shows how you can fillup permgen by preventing GC of permgen area.

Autres conseils

Garbage collection does happen in permgen space of heap too.

And static variables are garbage collected when their respective class loaders unload from memory.

String literal pool is probably never garbage collected.

EDIT If permgen is full, OutOfMemoryError : PermGen occurs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top