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

DialogParticipation.Register="{Binding}" Memory leak #4

Open
svantevit opened this issue Nov 5, 2019 · 2 comments
Open

DialogParticipation.Register="{Binding}" Memory leak #4

svantevit opened this issue Nov 5, 2019 · 2 comments

Comments

@svantevit
Copy link

I am using MahApps.Metro, v1.6.5.

MetroWindow with mah:DialogParticipation.Register="{Binding}" doesn't get disposed after the ShowDialog() call.

Example usage: I have two windows - MainWindow and MyDialogView. Each has it's own view model - MainWindowViewModel and MyDialogViewModel.
MainWindowViewModel contains a OpenDialogCommand, which opens the dialog view.
MyDialogViewModel contains a CloseCommand, which raises an OnClose event. The MainWindowViewModel handles the OnClose event and closes the dialog window.

For easier debugging I instantiate a large byte array in the MyDialogViewModel constructor. If I open and close the dialog window multiple times the memory usage only increases (by 1GB). But if I remove the DialogParticipation.Register parameter, then the memory usage gets decreased when the garbage collector runs.

I prepared an example here

@punker76
Copy link
Member

punker76 commented Nov 5, 2019

@kmetic You're correct with this memory leak. I must apologize that the hint for this is not easier to find. I'll put this on a better place.

https://github.com/MahApps/MahApps.Metro/blob/94fee344eb91f977a7289d5c8c7b89861605a198/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml#L26-L32

@svantevit
Copy link
Author

@punker76 thanks, I tested it and it works.

One question - I tried to unregister even if I didn't register before and it looks OK. Is it wrong to unregister all MetroWindows by default, event I you don't use DialogParticipation at all?

@punker76 punker76 transferred this issue from MahApps/MahApps.Metro May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants