由于Windows应用商店应用中的GridView导致内存泄漏

时间:2013-01-24 06:02:42

标签: xaml memory-leaks windows-store-apps winrt-xaml

我有以下GridView

<GridView
            x:Name="itemGridView" 
            AutomationProperties.AutomationId="ItemsGridView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Grid.RowSpan="2"
            Padding="116,136,116,46"
            SelectionMode="Single"
            IsSwipeEnabled="false"
            Visibility="Collapsed">

                <GridView.ItemTemplate>
                    <DataTemplate>
                        <!--<Border BorderBrush="DarkSeaGreen" BorderThickness="1">-->
                        <Grid Background="{Binding objBackgroundColor}" Opacity="1" Width="400" Height="80">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30"></RowDefinition>
                                <RowDefinition Height="*"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock Text="{Binding objCustomTestPaper.Name}" TextWrapping="Wrap"  FontWeight="SemiBold" VerticalAlignment="Top" Foreground="{Binding objForegroundColor}" Style="{StaticResource TitleTextStyle}" FontSize="20" MaxHeight="25"  Margin="10,5,10,0" />
                            </Grid>
                            <Grid Grid.Row="1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"></ColumnDefinition>
                                    <ColumnDefinition Width="*"></ColumnDefinition>
                                    <ColumnDefinition Width="120"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <!--<Image Grid.Column="0" Height="35" VerticalAlignment="Center" HorizontalAlignment="Center" Source="Assets/paper.png"></Image>-->
                                <StackPanel Grid.Column="0" Margin="5,7,0,0">
                                    <callisto:Rating  FontStretch="SemiCondensed" ItemCount="5" Value="{Binding objCustomTestPaper.TestRating}" FontWeight="Light" VerticalAlignment="Bottom"  Margin="0,2,5,1" Background="Transparent"  HorizontalAlignment="Left" Foreground="{Binding objForegroundColor}" IsHitTestVisible="False" FontSize="12" >
                                    </callisto:Rating>
                                    <StackPanel  Orientation="Horizontal" HorizontalAlignment="Left">
                                        <TextBlock Text="Attempted by others:" Margin="4,0,0,0" FontSize="12" FontWeight="Light" Foreground="{Binding objForegroundColor}"></TextBlock>
                                        <TextBlock Text="{Binding objCustomTestPaper.AttemptCount}" FontWeight="SemiBold" Margin="5,0,0,0" FontSize="12" Foreground="{Binding objForegroundColor}"></TextBlock>
                                        <TextBlock Text="times" Margin="3,0,0,0" FontSize="12" FontWeight="Light" Foreground="{Binding objForegroundColor}"></TextBlock>
                                    </StackPanel>
                                </StackPanel>
                                <StackPanel VerticalAlignment="Stretch" Grid.Column="2" Margin="0,0,0,0" >
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                                        <TextBlock Text="Time:" FontSize="16" Foreground="{Binding objForegroundColor}" VerticalAlignment="Bottom" FontWeight="SemiLight"></TextBlock>
                                        <TextBlock Text="{Binding strTestDuration}" Margin="5,0,0,0" FontSize="18" VerticalAlignment="Bottom" Foreground="{Binding objForegroundColor}" FontWeight="SemiLight"></TextBlock>
                                    </StackPanel>
                                    <StackPanel  Margin="0,2,0,0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                                        <TextBlock Text="Points:" FontSize="16" Margin="0,0,0,0" VerticalAlignment="Bottom" Foreground="{Binding objForegroundColor}" FontWeight="SemiLight"></TextBlock>
                                        <TextBlock Text="{Binding objCustomTestPaper.TotalMarks}" Margin="5,0,0,0" VerticalAlignment="Bottom" FontSize="18" Foreground="{Binding objForegroundColor}" FontWeight="SemiLight"></TextBlock>
                                    </StackPanel>
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>

            </GridView>

它正常工作并成功加载数据但是当我按下后退按钮时,数据仍保留在内存中(不可用)并在各种访问页面时不断增加。我不知道如何在调用GridView方法时清除OnNavigationFrom(,)的项目。我正在尝试使用objGridView.Items.Clear(),但它会抛出一些HRXXXX例外。

0 个答案:

没有答案