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

Memory leak created by the ColumnStylesHelper #3972

Closed
lipchev opened this issue Nov 21, 2020 · 4 comments · Fixed by #3973
Closed

Memory leak created by the ColumnStylesHelper #3972

lipchev opened this issue Nov 21, 2020 · 4 comments · Fixed by #3973
Labels
Milestone

Comments

@lipchev
Copy link
Contributor

lipchev commented Nov 21, 2020

Describe the bug

The DataGridColumnStylesHelperExtension is attached but never detached from the grid, leaving a memory leak with the Columns.CollectionChanged handler. This causes the whole window that is hosting the data grid to remain in memory.

Steps to reproduce

  1. Replace the albums list view in the CleanWindowDemo.xaml with an equivalent data grid
  2. Open and close the CleanWindowDemo

Expected behavior

When the parent is unloaded the memory is liberated

Actual behavior

The CleanWindowDemo window is retained in memory via the grid and the DataGridColumnStylesHelperExtension (see screenshot below)
Repeating the same steps with the mah:DataGridHelper.ColumnStylesHelper="{x:Null}" and the problem no longer occurs

Environment

MahApps.Metro version: v2.0.0
Windows build number: Win10 1909 [Version 10.0.18363.836]
Visual Studio: 2019 16.6.0
Target Framework: .Net Core 3.1 (v4.5.2, v4.7.2)

Screenshots

image

@lipchev lipchev added the Bug label Nov 21, 2020
@lipchev
Copy link
Contributor Author

lipchev commented Nov 21, 2020

Ouch, I just realized there is only one instance of the DataGridColumnStylesHelperExtension markup extension ever created.

@punker76
Copy link
Member

@lipchev Correct, for each DataGrid. But I still can not reproduce a memory leak with this extension.

@lipchev
Copy link
Contributor Author

lipchev commented Nov 21, 2020

The attach is called per grid, but it only overrides the private DataGrid field

@lipchev
Copy link
Contributor Author

lipchev commented Nov 21, 2020

Cool, I tried returning a new instance in the ProvideValue and the leak is gone (even without calling detach)

@lipchev lipchev changed the title MemoryLeak created by the ColumnStylesHelper Memory leak created by the ColumnStylesHelper Nov 22, 2020
@punker76 punker76 added this to the 2.4.0 milestone Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants