Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
If c implements ICommand, then setting ListView.RefreshCommand = c will subscribe to c.CanExecuteChanged in order to prevent the command c from being called when that is not allowed. So far so good.
The problem is that XF does not unsubscribe from the event, when the page containing the ListView is pop'ed from the navigation stack. Therefor the ListView can not be reclaimed by the GC until the command is GC'ed. If the command c is long lived (as is typical with commands living in the ViewModel layer of MVVM), then that may not happen until the process exits.
I have observed this behaviour on Android with XF 1.4.2, but I suspect it is a problem on all platforms.
As a work-around, don't set the ListView.RefreshCommand. Instead subscribe to ListView.Refreshing event and handle the command invocation by your self.
When the RefreshCommand is set to null, we do unsubscribe for the event, so that's an easier work around for you.
But when should I set the RefreshCommand to null? When the user press the back button, the page is pop'ed outside my code. Which event should I react to?
My workaround avoid this issue all together by never subscribing to ICommand.CanExecuteChanged. I can always check in the ListView.Refreshing event, if the command can execute or not.
Obviously I would prefer for XF to automatically unsubscribe from ICommand.CanExecuteChanged when the view is not visible.
I can confirm this.
However, I have tried to reproduce the memory leak on top of https://github.com/xamarin/Xamarin.Forms/pull/524 but wasn't able to. I'll try again when it's merged.
We are unable to reproduce this issue with the information given. If you are still experiencing this issue with Xamarin.Forms 2.3.4+ and when using FormsAppCompat in your Android project, please file a new bug report and provide a repro project so we can investigate further. Thanks!