There is nothing special about static members here. The finalize
method is called on an object when the object is being garbage collected. An object is being garbage collected when the object is no longer reachable from any part of the application.
The only difference is that static members are reachable for a longer period of time because of the way they are referenced. A static member is referenced by a class while the class is referenced by its class loader. Most class loaders have a long life time (the bootstrap class loader lives as long as the JVM is running) and rarely become eligible for Garbage collection, so for this reason the static members are still referenced long after any instances of that class have been garbage collected.
So the list
in your example is not tied to instances of your Finalizer
class, it is tied to the Finalizer
class itself. The field and instances of the class are garbage collected separately, the static
does not affect the call to finalize
for the instances of the class.
One other thing to be aware of in case you didn't know, finalizers might never run if the garbage collector never runs. If you have a lot of memory and a small short lived application, the garbage collector might not bother to reclaim any memory before your application exists.