コード例 #1
0
        public void WeakReferenceGetsFreedButHashCodeRemainsConstant() {
            var obj = new object();
            var wrap = new WeakReferenceWrapper(obj);
            int hashcode = wrap.GetHashCode();

            obj = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();

            wrap.IsAlive.Should().Be.False();
            wrap.Target.Should().Be.Null();
            wrap.GetHashCode().Should().Be(hashcode);
        }