How are finalizers different from C++ destructors?
Java programming language objects are not explicitly deleted and do not have destructors. Instead they are implicitly garbage collected when the JVM realizes your program can no longer access them. This technology is not based on reference counting and will cope with circular references. Every object has a routine called finalize() which will be called before the object is collected. This is the nearest equivalent to C++’s destructor. However, it is not a good idea to rely on finalization for the timely freeing of resources. This is because garbage collection and hence finalization may be arbitrarily delayed, and may never happen at all if the program terminates before it runs out of memory. You should instead provide your objects with methods similar to Graphics.dispose() to free resources, and call the dispose() method explicitly when you have finished using them – typically within the “finally” clause of a “try/catch” block. You may then call your dispose() method from within your f