Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 如何修复xamarin.Forms组件的内存泄漏问题。?_Performance_Xamarin_Memory Leaks_Xamarin.ios_Xamarin.android - Fatal编程技术网

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

Performance 如何修复xamarin.Forms组件的内存泄漏问题。?,performance,xamarin,memory-leaks,xamarin.ios,xamarin.android,Performance,Xamarin,Memory Leaks,Xamarin.ios,Xamarin.android,目前,我正在创建一个类似于Xamarin滑块的自定义组件。其中我遇到了一些内存泄漏。为了测试这一点,我在NavigationPage中创建了几个控件,并通过单击按钮移动到该页面(我使用Xamarin profiler检查内存分配)。我回去了,记忆没有释放。再次导航时,内存不断增加。我尝试过提供弱引用、使用dispose方法转储和GC收集。。等等, 我用xamarin滑块替换了自定义组件。但我也遇到了同样的内存分配问题 我已经把我的样品贴在下面了。我对导航页面做了什么错事吗 [xaml] <

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

我用xamarin滑块替换了自定义组件。但我也遇到了同样的内存分配问题

我已经把我的样品贴在下面了。我对导航页面做了什么错事吗

[xaml]

<ContentPage.Content>
    <Button Text="SLider Page" Clicked="Handle_Clicked"/>
</ContentPage.Content>
[滑动页面]

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;
    }
}

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


您可以使用override
OnDisappearing
在当前页面中的所有资源消失之前将其清除(Dispose/设置为null),并手动调用
GC.Collect()
。我强烈推荐此视频,以帮助进行性能调整:
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;
    }
}