Skip to content

Commit

Permalink
Merge pull request #1346 from AArnott/fixserializedTaskLeak
Browse files Browse the repository at this point in the history
Fix `JoinableTaskContext.serializedTasks` memory leak
  • Loading branch information
AArnott authored Aug 13, 2024
2 parents cc929f4 + a47707d commit 243b960
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Microsoft.VisualStudio.Threading/JoinableTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,14 @@ internal void Complete(Task wrappedTask)
{
if (!this.IsCompleteRequested)
{
// This must be done *before* setting IsCompleteRequested so that the TaskId property will still return the value we need.
ulong? taskId = this.token?.TaskId;

this.IsCompleteRequested = true;
if (this.token?.TaskId is ulong taskId)

if (taskId.HasValue)
{
this.JoinableTaskContext.RemoveSerializableIdentifier(taskId);
this.JoinableTaskContext.RemoveSerializableIdentifier(taskId.Value);
}

if (this.mainThreadQueue is object)
Expand Down

0 comments on commit 243b960

Please sign in to comment.