How long lasts the unicity (if any) of the System.identityHashCode()?

N

NOBODY

(sorry for crosspost, I was mistakenly in comp.lang.java.databases)

How long lasts the unicity (if any) of the System.identityHashCode()?

I created code that keep track of seen identityhashcodes for instances
created and unreferenced in a loop.

**** I was surprised to see that these identityhashcode can be reused! ****

The language spec says noting about the unicity of those (at any given
time) and especially not for periods of tiem.

Spec menyions that most jvm would use the heap address (which would explain
why these identityhashcode could be reused)

**** The question is:

At what time is an identityhashcode invalidated and reusable?
If I have a finalize() method, at which time the object is considered
unreferenced, could its identityhashcode be reused while the finalize() is
running?

My problem is that I associated data to an object, in an external
diskcache, by a key whose value is the identityhashcode, (trying to make
the key unique), and I must garbage collect it.
 
D

David Zimmerman

NOBODY said:
(sorry for crosspost, I was mistakenly in comp.lang.java.databases)

How long lasts the unicity (if any) of the System.identityHashCode()?

I created code that keep track of seen identityhashcodes for instances
created and unreferenced in a loop.

**** I was surprised to see that these identityhashcode can be reused! ****

The language spec says noting about the unicity of those (at any given
time) and especially not for periods of tiem.

Spec menyions that most jvm would use the heap address (which would explain
why these identityhashcode could be reused)

**** The question is:

At what time is an identityhashcode invalidated and reusable?
If I have a finalize() method, at which time the object is considered
unreferenced, could its identityhashcode be reused while the finalize() is
running?

My problem is that I associated data to an object, in an external
diskcache, by a key whose value is the identityhashcode, (trying to make
the key unique), and I must garbage collect it.

They don't have to be unique at all. The only contract you have is that
if they are different, the objects are not equal. There is nothing to
prevent asn implementation from returning the same number for every
object. (This will result in horrible hash maps, but they'll work.) You
can not depend on identityHashcode() giving unique numbers. It just
doesn't have to.
 
D

Dario

NOBODY said:
**** The question is:

At what time is an identityhashcode invalidated and reusable?

After the finalization *and* if no more references to the object are
availables (please note that during a finalize invocation you can store
the reference somewhere and so the reference (i.e. the address) is still
used).
If I have a finalize() method, at which time the object is considered
unreferenced, could its identityhashcode be reused while the finalize() is
running?

See previous answer.
My problem is that I associated data to an object, in an external
diskcache, by a key whose value is the identityhashcode, (trying to make
the key unique), and I must garbage collect it.

- Dario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top