I am new to GC and wondering what does garbage collector collect besides reference that are no longer being referencing by any variables ? The following is the list that I want to check
- Do primitive types (int, double, float, char….) get GC-ed ?
- Do static variables get GC-ed ?
- Do final variables get GC-ed (I think since it’s marked as immutable, so there’s nothing to collect) ?
- Do all the methods (both static and non-static) get GC-ed ?
- Do threads get GC-ed ?
GC doesn’t collect any references, it just frees the objects (memory on heap) which are no more reachable.
Static is special memory location and associated with class/classloader. If class/classloader un-deployed then static content will be removed from memory.
Primitive types if associated with object (class variables), then they will be GCed when object is not reachable.
If local variables/param variables, they will be on stack, so as soon as method execution completed, they are reclaimed.