From fc6211cacaf756d01f383c92c703124485a3acaa Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 9 Dec 2016 22:17:28 -0800 Subject: [PATCH] Regression test for https://github.com/dotnet/coreclr/pull/8580 --- .../ConditionalWeakTableTests.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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() {