Xamarin iOS memory leaks everywhere

I have shipped a non-trivial app written with Xamarin. Many others have as well.

“Garbage collection” isn’t magic. If you create a reference that is attached to the root of your object graph and never detach it, it will not be collected. That’s not only true of Xamarin, but of C# on .NET, Java, etc.

button.Click += (sender, e) => { ... } is an anti-pattern, because you don’t have a reference to the lambda and you can never remove the event handler from the Click event. Similarly, you have to be careful that you understand what you’re doing when you create references between managed and unmanaged objects.

As for “We’ve done our own MVVM arch”, there are high profile MVVM libraries (MvvmCross, ReactiveUI, and MVVM Light Toolkit), all of which take reference/leak issues very seriously.

Leave a Comment