finalization vs References

Per Bothner per@bothner.com
Thu May 11 12:14:00 GMT 2000


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

AltStyle によって変換されたページ (->オリジナル) /