Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabItem-ComboBox MemoryLeak #9827

Open
D-Bracket opened this issue Sep 21, 2024 · 1 comment
Open

TabItem-ComboBox MemoryLeak #9827

D-Bracket opened this issue Sep 21, 2024 · 1 comment
Labels
Investigate Requires further investigation by the WPF team.

Comments

@D-Bracket
Copy link

Description

If you create a UserControl, with an empty ComboBox () then use that UserControl in a TabItem of a TabControl, the UserControl is not beeing reclaimed by the GC after you Remove the TabItem.

Reproduction Steps

  1. Create UserControl with ComboBox
  2. Create TabControl in for example MainWindow
  3. Add TabItem with UserControl as Content.
  4. Remove the TabItem. (UserControl is not beeing reclaimed by GC)

Expected behavior

UserControl should be collected by GC.

Actual behavior

UserControl with a ComboBox is not getting garbage collected after removing TabItems from a TabControl, due to a handler set by the ItemContainerGenerator of the ComboBox (ItemContainerGenerator EventHandler).

Regression?

No response

Known Workarounds

No response

Impact

The severity of the leak of course depends on the UserControl.

Configuration

OS: Windows 10/11
.NET Version: .NET8
Visual Studio: VS2022
Architecture: x64

Other information

Minimal repro:
I have built repository showcasing the issue:
https://github.com/D-Bracket/WPF.MemoryLeak.Tests

TabControl_Memory_Leak_1_TabItems_Added_Afterwards_Removed
TabControl_Memory_Leak_3_UserControls_Are_Not_Reclaimed

@harshit7962 harshit7962 added the Investigate Requires further investigation by the WPF team. label Sep 23, 2024
@h3xds1nz
Copy link
Contributor

@D-Bracket Using your repro, there's no memory leak. As you can see, I'm on tab item 25 and the previous ones have been collected.

First screenshot is triggering the collection early while always keeping 1 tab item, second is spawning about 40 of them, then removing them and waiting for GC to happen naturally.

Image

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

3 participants