Forum Xamarin Xamarin.Forms

GTK - Why are multiple renderer instances being created?

I'm using Xamarin.Forms with a GTK platform and I'm seeing situations where multiple renderer instances are being created and not destroyed. I was able to replicate the issue with a small code sample to post here. Every time the button on this page is clicked, it makes 1 more label renderer instance than the last time it was clicked (e.g. on the 100th click it makes 100 new label renderer instances, etc). A large part of my application is built around adding and removing Views. Situations like this are creating memory leaks and adding to my page navigation time. Is there anything I can do to avoid this or have it reuse renderers?


        <StackLayout x:Name="PageStack">
            <Button Clicked="Button_Clicked"/>


namespace Example
    public partial class ExamplePage : ContentPage
        StackLayout stack;
        Label label;

        public ExamplePage()

            stack = new StackLayout();
            label = new Label();

        private void Button_Clicked(object sender, EventArgs e)


  • JohnHardmanJohnHardman GBUniversity admin
    edited August 2019


    I don't use GTK, but if implementation on GTK is similar to other platforms, I wonder if you may be hitting this - (which was created as a result of ).

    Undocumented, and incredibly confusing as a result until you realise it is being done, is that some (most) renderers call GC.SuppressFinalize . As a result, the renderers' finalizers are not called. If you have created custom renderers and are checking for the finalizers to be called to see if there are memory leaks, you will get an unexpected result as the cleanup is being done in the dispose handler, with the finalizer not being called. Cleanup is being done (hopefully - see caveat below), it's just the finalizers are not being called.

    Caveat: Note that the last time I checked (Xamarin.Forms 3.x, I haven't checked on 4.x yet), there were still renderers that were not cleaning up correctly, but those were a small minority.

  • knierknier Member

    In the case that I posted, the Dispose method doesn't get hit while you're still on the page. I observed this for custom renderers and the default renderers. Also, disposing is only half the problem. I don't think Xamarin should be creating multiple renderers for one instance of a View.

Sign In or Register to comment.