Thursday, 28 June 2018

Why Static Object and variables never dies


Never dies = Never Garbage collected = Live as long as JVM instance runs

Why never garbage collected ?




Because all Class level details, including all static variable(primitives value and reference values not the actual object actual object will anyway be there in Old/Young gen, only the references ) are
stored in "PermGen" space of Heap.


PermGen :

Holds --> Classloaders objects, which in turn loads classes, hence they hold reference of class they loaded, since statitic variables are references by classes, hence its reference is hold by classloader.

So till the classoader instance itself is destroyed , the static objects lives


When a class loader instance gets GCdown vote
accept
A class in Java can be garbage-collected when nothing references it. In most simple setups this never happens, but there are situations where it can occur.
There are many ways to make a class reachable and thus prevent it from being eligible for GC:
  • objects of that class are still reachable.
  • the Class object representing the class is still reachable
  • the ClassLoader that loaded the class is still reachable
  • other classes loaded by the ClassLoader are still reachable
When none of those are true, then the ClassLoader and all classes it loaded are eligible for GC.

Can permGen data gets garbage collected ? If yes, then Why permGen
TBC