Two objects which co-exist in time in the same AppDomain
may not have the same hash code, but an object which is created, prints out its hash code, then gets garbage collected may share a hash code with another object which is created later.
In fact, I'm not sure where that documentation comes from - the docs for object.GetHashCode
show this:
The default implementation of the GetHashCode method does not guarantee unique return values for different objects. Furthermore, the .NET Framework does not guarantee the default implementation of the GetHashCode method, and the value it returns will be the same between different versions of the .NET Framework. Consequently, the default implementation of this method must not be used as a unique object identifier for hashing purposes.
Note the first part about there not being a guarantee of it being unique for different values.
As for the bit about it not being a good hash code - that doesn't feel particuarly significant to me. If you only want reference equality, I think you're fine to not override GetHashCode
/Equals
.
You may get some hash collisions, but IMO it's very unlikely to be significant. The docs could certainly be clearer (I suspect the part about the method not being used as a unique object identifier for hashing purposes is talking about hashing for security) but I think you should be fine.