GC & The "Expensive Object" Problem

Bill Frantz frantz@communities.com
Fri, 07 May 1999 15:23:41 -0700


At 11:48 PM 5/6/99 -0700, Mark S. Miller wrote:
>At 11:43 AM 5/6/99 , Bill Frantz wrote:
>>[+] It is also necessary that exhaustion of the externally-expensive
>>resource trigger GC.  A fine example is running out of OS file handles.
>>Current JVMs require that you close files if your application needs to
>>access a large number of files.
>
>Is it necessary if the local gc can guarantee that expensive objects get 
>collected & finalized in a prompt manner?  (Though defining "prompt" can get 
>slippery.)

[-]You need to run finalization during the unit of operation that failed.
In the case of running out of file handles, you have the situation that an
open fails with garbage File objects which refer to OS-opened files.  You
would like to have those garbage File objects be collected, and their
"finalize" method run to close the OS-open and free up the file handle.
Then the Java-open would retry and as far as the Java code is concerned,
the open succeeds on the first try.  That kind of recovery makes running
out of file handles during an open behave the same as running out of memory
during a "new".