I do not believe that the garbage collection will run automatically (and hence not your finalize method). If may not run even if you ask it to do so (kind of like trying to teach a cat to sit). I was able to get the output you are looking for with the following slightly modified code:
Note that although I have asked for the garbage collection to execute, it may not. At the very least, you have to provide some objects to be available for garbage collection before the application is finished which is what I have done by setting the object references to null.
Does this help?
Joined: Oct 04, 2004
thank you, its working. But can we always run the gc successfully whenevr we want.