Re: Alternative to System.runFinalizersOnExit()?
Twisted wrote On 11/14/06 16:17,:
Thomas Hawtin wrote:
'file' is not a resource. new FileOutputStream(file) is. If the
BufferedOutputStream throws an OOME, then it will leak. There is no
local variable referring to the resource.
If the BufferedOutputStream throws an OOME, then it will leak a little
dribble after it's evidently already lost an ocean. Put it in
perspective will you? :)
The important thing isn't the ocean that's already
been lost, but the tiny dribble that remains. It's that
little dribble that will -- or won't -- suffice to get
you out of Death Valley (a part of California that was
once completely underwater but is now arid and HOT).
You're probably not going to get very far after the
JVM throws an OOME at you, and most Java applications will
just die as you've described elsethread. A few, though,
will catch the OOME and attempt a clean shutdown rather
than an uncontrolled exit. That last-ditch effort will
operate under conditions of extreme memory scarcity, and
the little dribble you disparage might tip the balance.
It is frightening and unpleasant to make an emergency
landing on a foam-covered runway flanked by fire and rescue
vehicles (or so I'm told by an acquaintance who's done it,
not once but twice). Nonetheless, she'd rather do it a
third time than experience even one crash.
--
Eric.Sosman@sun.com