Re[2]: [gclist] Finalization and object orientation.

Scott Meyer smeyer@us.oracle.com
Thu, 27 Mar 1997 20:50:45 -0800


At 07:59 PM 3/27/97, Colvin, Greg wrote:

>File handles seem to be the kind of resource that a finalizer 
>is handy for: they have no owner but the process, they are 
>easily encapsulated in a class, and it can be hard to know 
>statically when the last user of file is gone.

I'd point out that in at least one window system, X, a
file handle is associated with a window or set of windows.
Sometimes open file handles are associated with entities
which are visible to the outside world, sometimes not.

The key issue is latency, the delta between the time when the
opened file object becomes garbage and the time when the
finalizer is run (and closes it).  To the extent that file
handles are not attached to things that the outside world
cares about, treating them as just another sort of "memory"
and firing off a gc when you run out of them is fine.  Conversely,
if you actually care about latency, finalization is not
the ticket (though you might want it around to keep things from
crashing).

Dragging this all back to the original point about OO and
encapsulation, if you care about latency then you need to
deal with latency inside the encapsulation you provide.
Finalization (however well specified) won't do it for you.



Scott Meyer                                   415 506 0987
Principal MTS                                 mailto:smeyer@us.oracle.com
Oracle - Languages & Relational Technology    standard disclaimer