diff --git a/src/System.Runtime/tests/System/Runtime/CompilerServices/ConditionalWeakTableTests.cs b/src/System.Runtime/tests/System/Runtime/CompilerServices/ConditionalWeakTableTests.cs index 1f0f955571a3..7a64f1e39080 100644 --- a/src/System.Runtime/tests/System/Runtime/CompilerServices/ConditionalWeakTableTests.cs +++ b/src/System.Runtime/tests/System/Runtime/CompilerServices/ConditionalWeakTableTests.cs @@ -183,6 +183,28 @@ public static void Concurrent_GetValue_Read_Remove_SameObject() }); } + [Fact] + public static void AddRemove_DropValue() + { + var key = new object(); + var value = new object(); + + var cwt = new ConditionalWeakTable(); + + cwt.Add(key, value); + cwt.Remove(key); + + // Verify that the removed entry is not keeping the value alive + var wrValue = new WeakReference(value); + value = null; + + GC.Collect(); + Assert.False(wrValue.IsAlive); + + GC.KeepAlive(cwt); + GC.KeepAlive(key); + } + [Fact] public static void GetOrCreateValue() {