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.
Christophe Vanfleteren - 02 Feb 2004 09:09 GMT
> How long lasts the unicity (if any) of the System.identityHashCode()?
>
[quoted text clipped - 20 lines]
> diskcache, by a key whose value is the identityhashcode, (trying to make
> the key unique), and I must garbage collect it.
Don't do that. A hashcode is never guaranteed to be unique. You'll just have
to generate your own PK's.

Signature
Kind regards,
Christophe Vanfleteren