I understand that if you hava finalize() in your class it is run when an object is gc'd. Is it run only on a forced gc?
I ask because in the program below I believe I have 3 objects to be cleaned up but it looks as if finalize only runs 2 times. the code is from the "thinking in Java" book.
First of all you can't forge the GC. You can request it. The aBook is still in scope and because of that it's not GC'ed.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
You should never attempt to call finalize() (unless under the catch-all excuse of "I just wanted to see what happens if . . . "); if you call it once when it isn't necessary, it might not be called when necessary by the JVM.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.