finalization vs References
Boehm, Hans
hans_boehm@hp.com
Thu May 11 12:52:00 GMT 2000
Finalization isn't free, but it isn't that expensive either. Every
finalizable object requires the allocation of another small object to keep
track of it inside the collector. All of these small objects are examined
twice during every collection.
I haven't measured this, but I would expect that if you had a heap full of
small objects, and every oject in the heap somehow became finalizable, with
an empty finalizer, you would roughly double or triple GC costs, in both
time and space. There is no change in the asymprotic behavior; GC costs are
still linear in the heap size.
The current incremental collector doesn't handle large volumes of
finalizable objects very well, since much of the finalization work is done
with the world stopped. Fixing that is a small matter of programming ...
I haven't thought enough recently about Java 2 references. I suspect all of
these mechanisms have comparable costs.
Hans
> -----Original Message-----
> From: Per Bothner [ mailto:per@bothner.com ]
> Sent: Thursday, May 11, 2000 12:10 PM
> To: java-discuss@sourceware.cygnus.com
> Subject: finalization vs References
>>> I gather that finalization is rather expensive, at least as
> implemented in libgcj. Any feelings on whether it is more
> or less expensive that using Java2 References? I realize
> gcj does not yet support Reference objects, but I would be
> interested in seeing some thoughts. (People working on
> the libgcj gc implementation certainly should have at least
> a strategy for implementing Reference objects.)
>> For example, consider javax.swing.text.Position. This references
> an offset in Document, but the Document must be able to update the
> offset. I can see how to implement this using finalization,
> or using WeakReference. The former seems simpler, and more portable.
> Also, using WeakReference requires one extra WeakReference
> object for each Position, which for a "small" object like Position
> is a substantial extra cost.
>> So it seems clear: Unless finalization is substantially more expensive
> than WeakReferences, it is the preferable feature to use. Is it more
> expensive?
>> In JEmacs (jemacs.sourceforge.net), my reimplementation of
> Emacs using Kawa and Swing, I implemented a Position as an
> index into a table managed by the Document. The Position's
> finalizer reclaims the index from the Document's table.
>> By the way: It looks like I will be writing alternative
> implementations of various Swing text interfaces. I have
> re-implemented Content and Position, and it looks like I
> will be implementing an alternative StyledDocument class
> with Elements. Replacements for View may follow, but are
> further off. If someone else is working in re-implementing
> Swing, especially the text classes, we should perhaps work together.
> --
> --Per Bothner
> per@bothner.com http://www.bothner.com/~per/
>
More information about the Java
mailing list