Re: finalize()

So Bloch says its a mistake to use finalize to manage system resources, but its a good idea to use it as a "safety net", which is what I guess you are advocating. It occurs to me that probably closes itself in the finalizer, just like FileInputStream. I wonder why linux behaves differently?
Bob Simons wrote:
I looked in the source code for the (as an example) to see if Java's file classes use the finalize() method. They do.

* Ensures that the <code>close</code> method of this file input stream is
     * called when there are no more references to it.
     * @exception  IOException  if an I/O error occurs.
     * @see
    protected void finalize() throws IOException {
    if (fd != null) {
        if (fd != {

So I don't yet know what Josh Bloch's book says specifically, but Sun uses the finalize method in the actual Java code.


Bob Simons
Satellite Data Product Manager
Environmental Research Division
NOAA Southwest Fisheries Science Center
1352 Lighthouse Ave
Pacific Grove, CA 93950-2079
<>< <>< <>< <>< <>< <>< <>< <>< <><

  • 2006 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: