|
Prev: overwriting arrays
Next: Method chaining with generics
From: Paul J. Lucas on 23 Aug 2005 11:38 According to: http://www.unix.org.ua/orelly/java-ent/jnut/ch03_03.htm that says in part: The Java interpreter can exit without garbage collecting all outstanding objects, so some finalizers may never be invoked. Is this still true in Java 1.4 and later? - Paul
From: Ingo R. Homann on 23 Aug 2005 11:50 Hi, Paul J. Lucas wrote: > According to: > > http://www.unix.org.ua/orelly/java-ent/jnut/ch03_03.htm > > that says in part: > > The Java interpreter can exit without garbage collecting > all outstanding objects, so some finalizers may never be > invoked. > > Is this still true in Java 1.4 and later? I don't know, but in newer Versions there is a Shutdown-Hook-mechanism for dealing with that. Ciao, Ingo
From: Paul J. Lucas on 23 Aug 2005 12:50 Ingo R. Homann <ihomann_spam(a)web.de> wrote: > > Paul J. Lucas wrote: > > According to: > > > > http://www.unix.org.ua/orelly/java-ent/jnut/ch03_03.htm > > > > that says in part: > > > > The Java interpreter can exit without garbage collecting > > all outstanding objects, so some finalizers may never be > > invoked. > > > > Is this still true in Java 1.4 and later? > > I don't know, but in newer Versions there is a Shutdown-Hook-mechanism > for dealing with that. I know, and that's not what I'm asking about. Why should *I* have to add a shutdown hook to call System.runFinalizers() ? I want to know if the JVM will *guarantee* that all finalizers will *automatically* be executed prior to JVM shutdown - Paul
From: Eric Sosman on 23 Aug 2005 13:58 Paul J. Lucas wrote: > Ingo R. Homann <ihomann_spam(a)web.de> wrote: >> >>I don't know, but in newer Versions there is a Shutdown-Hook-mechanism >>for dealing with that. > > > I know, and that's not what I'm asking about. Why should *I* > have to add a shutdown hook to call System.runFinalizers() ? I > want to know if the JVM will *guarantee* that all finalizers > will *automatically* be executed prior to JVM shutdown Ingo seems to be saying something slightly different: not that you should use a shutdown hook to run finalizers, but that you should use it for the cleanup you're now (it seems) trying to do in the finalizers. FWIW, the gurus (I am not one) seem to be unanimous in warning against using finalizers as destructors. Eckel puts it this way: Garbage collection is about memory, finalization is an aspect of garbage collection, therefore finalization is about memory and anything that isn't about memory is out of place in a finalizer. Bloch writes at length about the dangers of finalization, and recounts the tale of an OutOfMemoryError that was caused by relying on finalizers -- not by bug-ridden finalizers, mind you, but simply by reliance on them. Add to this some of the scarier passages where the Javadoc explains why System.runFinalizersOnExit() is deprecated (sounds like a hint, doesn't it?), and I think there are enough bad omens to make you consider other avenues ... -- Eric.Sosman(a)sun.com
From: Joan on 23 Aug 2005 16:49
"Paul J. Lucas" <pauljlucas.removethis(a)removethistoo.mac.com> wrote in message news:zpHOe.3801$Z87.2064(a)newssvr14.news.prodigy.com... > According to: > > http://www.unix.org.ua/orelly/java-ent/jnut/ch03_03.htm > > that says in part: > > The Java interpreter can exit without garbage collecting > all outstanding objects, so some finalizers may never be > invoked. > > Is this still true in Java 1.4 and later? My book says that if you execute "System.exit(0);" that it does an exit without doing anything else. |