CommunityToolkit / WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/communitytoolkit/
Other
5.9k stars 1.37k forks source link

Memoryleak on DataGrid TableHeader #4737

Open KenionX opened 2 years ago

KenionX commented 2 years ago

Describe the bug

Moving the mouse over the table headers on a DataGrid will cause an event handler leak, resulting in a Memoryleak on the control

Regression

No response

Reproducible in sample app?

Steps to reproduce

https://github.com/KenionX/Winui3MemoryLeak/tree/master

Move the mouse over the table headers

Expected behavior

No memory leak

Screenshots

devenv_2USYr4idPF

Windows Build Number

Other Windows Build number

No response

App minimum and target SDK version

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

17.2.6

Device form factor

Desktop

Nuget packages

CommunityToolkit.WinUI.UI.Controls.DataGrid 7.1.2 Microsoft.WindowsAppSDK 1.1.4 Microsoft.Windows.SDK.BuildTools 10.0.22621.1 MvvmGen 1.1.5

Additional context

No response

Help us help you

No.

ghost commented 2 years ago

Hello KenionX, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

michael-hawker commented 2 years ago

@RBrid I know you're busy, but I don't see where we'd be registering an event here in the Pointer Moved event or anything. If you had a couple of minutes to maybe point us in the right direction here, that'd be much appreciated. Thanks!

Arlodotexe commented 2 years ago

This issue is reproduceable on UWP: App1.zip

Arlodotexe commented 2 years ago

I'm still looking for what exactly causes this, but after investigating I've found that this line is causing extra allocations:

image

Commenting out the line, the memory increase goes away. Leaving the line there but removing all code in the handler, the memory increase comes back.

Attaching the event is causing this (not the event invocation or event handler), but for some reason it's only that one event. Still investigating.