Skip to content

Commit 98634f6

Browse files
authored
Try fix EventRoute weak memory leak (#9463)
Fixes #9467 GC is not reclaiming WPF control objects when they are removed from the visual tree, if tracing is enabled in a WPF application. This issue came from PR : Reduce allocations when tracing routed events by bgrainger · Pull Request #6700 · dotnet/wpf, a performance improvement for applications using tracing, by removing unnecessary allocations. However, while doing that, we don't clear the array which causes this issue. However, eventually these control objects are collected.
1 parent 1103ab7 commit 98634f6

File tree

1 file changed

+4
-2
lines changed
  • src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows

1 file changed

+4
-2
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ private void InvokeHandlersImpl(object source, RoutedEventArgs args, bool reRais
200200
TraceEventType.Stop,
201201
TraceRoutedEvent.InvokeHandlers,
202202
_traceArguments);
203-
}
204-
205203

204+
Array.Clear(_traceArguments);
205+
}
206206
}
207207
}
208208
else
@@ -273,6 +273,8 @@ private void InvokeHandlersImpl(object source, RoutedEventArgs args, bool reRais
273273
TraceEventType.Stop,
274274
TraceRoutedEvent.InvokeHandlers,
275275
_traceArguments);
276+
277+
Array.Clear(_traceArguments);
276278
}
277279

278280
}

0 commit comments

Comments
 (0)