mvvmlight icon indicating copy to clipboard operation
mvvmlight copied to clipboard

CanExecuteChanged memory leak in UWP

Open JamesNK opened this issue 6 years ago • 3 comments

Hi

I have a view model with a RelayCommand that is bound to the UI. I am reusing a single instance of that view model that is shared between pages. When navigating between pages the old view is thrown away and the single instance is bound to the new page.

I have noticed that the CanExecuteChanged event is being subscribed to by something in the UI and it is never being unsubscribed. The RelayCommand.CanExecuteChanged invocation list grows each time a new page is navigated to forever.

dotMemory: image

JamesNK avatar Feb 14 '18 01:02 JamesNK

Hi James,

Thanks for the feedback. Do you have a way to strip the code to the bare minimum so I can take a closer look?

Thanks Laurent

Laurent Bugnion, Microsoft- +41 79 537 78 08


From: James Newton-King [email protected] Sent: Wednesday, February 14, 2018 02:27 To: lbugnion/mvvmlight Cc: Subscribed Subject: [lbugnion/mvvmlight] CanExecuteChanged memory leak in UWP (#21)

Hi

I have a view model with a RelayCommand that is bound to the UI. I am reusing a single instance of that view model that is shared between pages.

I have noticed that the CanExecuteChanged event is being subscribed to by something in the UI and it is never being unsubscribed. The RelayCommand.CanExecuteChanged invocation list grows each time a new page is navigated to forever.

dotMemory: [image]https://user-images.githubusercontent.com/303201/36183425-1504da28-1193-11e8-8fda-29ca56672b0a.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/lbugnion/mvvmlight/issues/21, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AEscWaFOnzuvhbT2wpcBIB5HLD9V2l1Nks5tUjaKgaJpZM4SEqnb.

lbugnion avatar Feb 14 '18 06:02 lbugnion

Attached.

App1.zip

JamesNK avatar Feb 14 '18 22:02 JamesNK

Hi, I'm having the same issue with a WPF "Classic Desktop" app.

I attach a .zip with a sample project where the problem is present. In the example, the problem manifests itself if you continue to navigate between the two pages.

The issue seems to go avay if I use "InvokeCommandAction" in the XAML of "SubView" to trigger a command from an event instead of the "EventToCommand"

WpfMemoryLeak.zip

Using MvvmLight 5.4.1.1 and .NET Framework 4.7

HispidaBytes avatar Oct 08 '18 09:10 HispidaBytes