[gclist] Garbage collection and XML

Bill Foote Bill.Foote@eng.sun.com
Wed, 07 Mar 2001 10:31:50 +0100


"Richard A. O'Keefe" wrote:


> I don't know about Javascript, but in Java it is perfectly possible to
> have two String objects with the same (immutable!) state which must act
> the same for all future time, but have distinct identities.  A Java
> program which tried to keep track of which nodes strings came from by
> using String identities as keys could be confused if strings were shared.

Ah, good point.  It is theoretically possible to use string identities to
discriminate String objects.  You'd have to be mad to try, and it's not
easy, but you can:

    public class IdentityStringKey {
        private String value;

        ...

        public int hashCode() {
            return value.hashCode();
        }

        public boolean equals(Object other) {
            if  (other instanceof IdentityStringKey) {
                return ((IdentityStringKey) other).value == value;
            } else {
                return false;
            }
        }
    }

So I take back what I said.  With enough work, once actually could word a normative,
testable requirement of no String object sharing in a Java API.  It's hard to do
and doesn't makes sense, but it can be done.

Anyway, this is moot as it sounds like DOM didn't go that far.

Cheers,

Bill
-- 
Bill Foote                                         bill.foote @ sun.com
Java TV Standards Engineer          http://java.sun.com/products/javatv