Finalizers are unreliable to release resources and are a price to pay for the performance. They are called by the garbage collector when there are no more references to a resource, but we can't predict when this will happen.
Implement AutoCloseable instead (not Closeable, maintained for backward compatibility).
Use finalize() only as an additional check to remove resources.
Every time you use finalize(), you have to call also super.finalize(), because the superclass finalizer isn't called implicitly.
You can force the GC to call finalizers in two ways:
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.