Commit b45dea6b authored by Ben Adams's avatar Ben Adams Committed by Nick Craver

Clear ResultBox state prior to caching

parent 7c2f65af
...@@ -69,6 +69,9 @@ public static void UnwrapAndRecycle(ResultBox<T> box, bool recycle, out T value, ...@@ -69,6 +69,9 @@ public static void UnwrapAndRecycle(ResultBox<T> box, bool recycle, out T value,
var newCount = Interlocked.Decrement(ref box._usageCount); var newCount = Interlocked.Decrement(ref box._usageCount);
if (newCount != 0) if (newCount != 0)
throw new InvalidOperationException($"Result box count error: is {newCount} in UnwrapAndRecycle (should be 0)"); throw new InvalidOperationException($"Result box count error: is {newCount} in UnwrapAndRecycle (should be 0)");
// Clear state prior to recycling, so as not to root it
box.stateOrCompletionSource = null;
for (int i = 0; i < store.Length; i++) for (int i = 0; i < store.Length; i++)
{ {
if (Interlocked.CompareExchange(ref store[i], box, null) == null) return; if (Interlocked.CompareExchange(ref store[i], box, null) == null) return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment