Quoting "Shapira, Yoav" <[EMAIL PROTECTED]>: > > Howdy, > > >Not sure I buy "...will result in much more efficient memory > claiming...". > > Then benchmark it ;) You will see a difference.
Someone did, and you're right, there was a difference ;-): http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html#997455 The point is really that it depends. My issues are with the word "will" (as in it's always gonna be that way) and the implication that finalizers should be part of your normal implementation. I'd say finalilzers are specifically for abnormal situations where automatic memory management is insufficient for cleaning up an object's resources. And even then, you're still better off doing an explicit cleanup. > For a short-lived object, the benefits may be negligible as you say. My > scenario is for a long lived cache type object. In a full > implementation, an explicit clear method would be present as well, and > the finalize method would call the clear, but I wanted to put together > the simplest, clearest example. Sure, I understand the example has to be bite-sized. But even for a long-lived cache object, if it's not reachable I want it gone as quickly as possible, not when the VM gets a chance to run its finalizer. Yes, on average, it may not be an issue for the VM to do that, but I don't want to get bit by that ~100MB cache hanging around at the wrong time. > >the least, implementing a finalizer extends the lifetime of an object. > > True, but typically by very little and in this example, IMHO the > benefits (~100MB of memory cleaned up a second faster for an increase of > several microseconds in execution time of my benchmark run) far outweigh > this cost. Well, I guess in a typical situation that one second wouldn't make a difference either. But under heavy load you can't really make any claims about when the finalilzer gets run because it's unspecified. > >preferable to make it explicit (e.g. add a clear method to MyClass). > > An explicit clear method has its uses as well, and I nearly always > include them in all implementations. But so does the finalizer() in > ensuring the most efficient possible shutdown internally, without > relying on the user to call a clear() method. That just seems like too much of a generalization. In fact, it's possible that finalizers may never be run. I'm much happier with a system that behaves predictably and relying on finalizers is a step in the opposite direction. > Yoav Shapira > Millennium ChemInformatics > > > > This e-mail, including any attachments, is a confidential business > communication, and may contain information that is confidential, proprietary > and/or privileged. This e-mail is intended only for the individual(s) to > whom it is addressed, and may not be saved, copied, printed, disclosed or > used by anyone else. If you are not the(an) intended recipient, please > immediately delete this e-mail from your computer system and notify the > sender. Thank you. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]