none
StackPanel添加ManipulationMode="All"导致Page无法被释放 RRS feed

  • 问题

  • 大家好,

    本人有一个问题需要各位大侠帮助,问题描述,如下:

    在FirstPage中的一个StackPanel控件中由于需要接受手势操作,添加了ManipulationMode="All"属性。

    示例代码如下:

    <Page
        x:Class="DemoPage.FirstPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:DemoPage"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel x:Name="MySP" ManipulationMode="All">
                <Button Width="200" Height="200" Content="Test Button" Click="Button_Click"></Button>
            </StackPanel>
        </Grid>
    </Page>

    当从FirstPage迁到SecondPage后,发现FirstPage没有走~FirstPage()函数,也就是没有析构,

    在SecondPage中主动调GC.Collect()方法,也不能100%运行~FirstPage()函数,但是把StackPanel中的 ManipulationMode="All"属性删除,就可以运行~FirstPage()方法。

    各位大侠是否也发现过同样问题?

    现在我们的程序怀疑可能是这个问题导致了内存泄漏。


    2014年2月13日 6:48

全部回复

  • Hi,

    您可以发一个project到skyDriver,可以让我们来测试一下吗?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2014年2月14日 3:18
    版主
  • 由于各种原因不能够将工程上传给SkyDriver,劳驾您帮忙见一个工程测试下面的代码,谢谢了
    MainPage.CS
    
    public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
            }
    
            ~MainPage()
            {
                Debug.WriteLine(" ~MainPage ");
            }
    
            private void StackPanel_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
            {
    
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                (Window.Current.Content as Frame).Navigate(typeof(BlankPage1));
                GC.Collect();
            }
    
            private void StackPanel_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
            {
    
            }
    
            private void GCClick(object sender, RoutedEventArgs e)
            {
                GC.Collect();
    
            }
        }

    MainPage.xaml
    
    <Page
        x:Class="DemoPage.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:DemoPage"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" >
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel Orientation="Horizontal" ManipulationMode="All">
                <Button Width="200" Height="200" Content="Go to BlankPage" Click="Button_Click"></Button>
                <Button Content="Do GC Collect" Width="200" Height="200" Click="GCClick" Canvas.Top="199"/>
            </StackPanel>
        </Grid>
    </Page>

    BlankPage1.cs
     
    
    public sealed partial class BlankPage1 : Page
        {
            public BlankPage1()
            {
                this.InitializeComponent();
            }
    
            ~BlankPage1()
            {
                Debug.WriteLine("~BlankPage1");
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                this.Frame.GoBack();
            }
    
            private void GCClick(object sender, RoutedEventArgs e)
            {
                GC.Collect();
    
            }
        }

    BlankPage1.xaml <Page x:Class="DemoPage.BlankPage1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:DemoPage" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Orientation="Horizontal"> <Button Content="Go Back" Width="377" Height="208" Click="Button_Click_1"></Button> <Button Content="Do GC Collect" HorizontalAlignment="Left" Click="GCClick" Height="208" Width="377"/> </StackPanel> </Grid> </Page>

    2014年2月17日 8:21