Does static variables get garbage collected?
Answered
Does static variables get garbage collected?
Best answer
No, Static variables cannot be elected for garbage collection. They can be collected when the respective class loader (that was responsible for loading this class) is itself collected for garbage.
Static variables are referenced by Class objects which are referenced by Class loaders – so unless the ClassLoader itself becomes eligible for collection the static variables won’t be collected.