How are static variable treated by the garbage collector and where are they allocated memory? on the heap or stack (as member variables)
Please clarify this for me.
How are static variable treated by the garbage collector and where are they allocated
Share
Static variables are only eligible for garbage collection when the class itself is garbage collected — and classes are only eligible for garbage collection if the classloader which loaded them is garbage collected.
See JLS § 12.7:
Static fields are allocated on the heap.