如何修复xamarin.Forms组件的内存泄漏问题。

时间:2016-07-27 13:25:14

标签: performance xamarin memory-leaks xamarin.ios xamarin.android

目前我正在创建一个类似于Xamarin Slider的自定义组件。其中我遇到了一些内存泄漏。因此,为了测试这个,我在NavigationPage中创建了一些控件,并通过单击按钮移动到该页面(我使用Xamarin探查器来检查内存分配)。我回去了内存不释放。此外,在再次导航时,内存不断增加。我试过提供弱引用,使用dispose方法转储和GC收集等等,

我用xamarin Slider替换了我的自定义组件。但我遇到了相同的内存分配问题。

enter image description here

我在下面贴了我的样本。我对NavigationPages做错了什么。?

[XAML]

<ContentPage.Content>
    <Button Text="SLider Page" Clicked="Handle_Clicked"/>
</ContentPage.Content>

[CS]

 async void  Handle_Clicked(object sender, System.EventArgs e)
    {
        await Navigation.PushAsync(new SlidertPage());
    }

[滑块页面]

public class SlidertPage :ContentPage
{

    public SlidertPage()
    {

        StackLayout stack = new StackLayout();

        stack.Children.Add(new Slider() { HeightRequest = 200, WidthRequest = 200 });
        stack.Children.Add(new Slider() { HeightRequest = 200, WidthRequest = 200 });
        StackLayout stack2 = new StackLayout();

        stack2.Children.Add(new Slider() { HeightRequest = 200, WidthRequest = 200 });
        stack2.Children.Add(new Slider() { HeightRequest = 200, WidthRequest = 200 });

        StackLayout stack3 = new StackLayout();
        stack3.Orientation = StackOrientation.Horizontal;
        stack3.Children.Add(stack);
        stack3.Children.Add(stack2);
        this.Content = stack3;
    }
}

请在页面关闭时提供清除分配的任何建议。

0 个答案:

没有答案
相关问题