Originally posted by Chris Blades:
but exit the program.
True, if you exit the program all (file) handles will eventually be released. The thing is, you will more likely run into problems if you don't exit the program, and keep running. Especially on servers this happens a lot. The OS doesn't know you don't need the handle any more so it keeps it open.
Also here, eventually the garbage collector will collect your objects, and if the finalize method is written correctly the handle will be released, but everybody should know that you can never predict when it runs. In fact, I once had a semi-realtime system setup that was so swamped that it crashed with a memory error. Because all other threads had a higher priority (realtime, remember) the GC never even ran.