El jue, 08-09-2005 a las 15:51 +0100, Peter Edworthy escribió:
(...snip...)
> [long version]
> Cleaning up Strings that are only used in a particular classloader has
> a
> slight catch; because of the 'Strings containing the same characters
> are
> the same object' clause. This requires keeping a list of all currently
> created String objects that is checked at String object creation time
> to
> see if a reference to an existing object should be used or a new
> String
> object created. This list has to be outside of the gc link checking or
> no
> String would be gc'ed, but the list must also be informed when a
> String is
> gc'ed so as to remove it.

IIRC, the (JVM spec v2) requirement for .equals String literals to be
(==)identical only holds for Strings in the same .class file, but I
could be wrong.

In any case, interning all VM Strings in some sort of global weak set
would do the trick, as shared literals would remain referenced on
classloader collection, while unreferenced ones would be eligible for
collection. This is typically how symbols in lisp or smalltalk are
managed (most implementations don't even bother to use a weak structure,
so symbols are never collected). Basically this is what String.intern()
does, and nothing impedes us to actually use it for all Strings in the
VM.

Regards
Santiago
-- 
VP and Chair, Apache Portals (http://portals.apache.org)
Apache Software Foundation

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to