Creating a File object neither opens the file nor the contents are loaded into the memory. The GC will take care of the unreferenced object and will garbage collect them as and when required.
In case if you are shuting down the JVM, then at the time the JVM will release all the resources and will free the memory allocated for each resources. By resources I mean, the File opened, Socket connections, etc...
There is no method called close() in File class so that you can close an opened file. A file is not opened from a File object, rather an Input/ Output stream is associated with this file and using them we will be reading or writing data into the file.
Memory leak need not be worried in case of Java as, when JVM exits(normally) it releases all the memory allocated with in the process. You have to be careful in creating the objects and making the reference of unused instance variables to null, making the objects eligible for garbage collection. Any unreferenced objects will be garbage collected and the memory will be released. Referenced objects will not be finalised whether it is been used or not. So you have to make the unused reference variables to null.
Bipin, if you are coming from C/C++ background to Java then the point is that here in java you need not worry about malloc or free. The entire memory management is done by the JVM
Hope this helps.
[ February 27, 2003: Message edited by: Vijayakumar Arya ]