Xaml Windows Phone 8中ScrollViewer的内存使用情况

Xaml Windows Phone 8中ScrollViewer的内存使用情况,xaml,memory,windows-phone-8,Xaml,Memory,Windows Phone 8,我想知道是否有人知道如何在手机应用程序上设置属性或设置,以便ScrollViewer使用更少的内存缓存。我目前有一个在屏幕上显示图像的应用程序,即使有一个算法可以确保只有靠近屏幕或与屏幕相交的图像才可见,但当我碰巧在附近放大了很多图像时,我仍然会出现内存不足的情况 例如,下面的XAML将消耗掉300个内存中的125MB,而这只是空白的白色画布 <phone:PhoneApplicationPage x:Class="DemoScroller.MainPage" xmlns="http://

我想知道是否有人知道如何在手机应用程序上设置属性或设置,以便ScrollViewer使用更少的内存缓存。我目前有一个在屏幕上显示图像的应用程序,即使有一个算法可以确保只有靠近屏幕或与屏幕相交的图像才可见,但当我碰巧在附近放大了很多图像时,我仍然会出现内存不足的情况

例如,下面的XAML将消耗掉300个内存中的125MB,而这只是空白的白色画布

<phone:PhoneApplicationPage
x:Class="DemoScroller.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
        <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <Canvas Width="2000" Height="8000">
                <Canvas Width="990" Height="1990" Background="White"/>
                <Canvas Width="990" Height="1990" Canvas.Left="1010" Background="White"/>
                <Canvas Width="990" Height="1990" Canvas.Top="2000" Background="White"/>
                <Canvas Width="990" Height="1990" Canvas.Left="1010" Canvas.Top="2000" Background="White"/>
                <Canvas Width="990" Height="1990" Canvas.Top="4000" Background="White"/>
                <Canvas Width="990" Height="1990" Canvas.Left="1010" Canvas.Top="4000" Background="White"/>
            </Canvas>
        </ScrollViewer>
    </Grid>
</Grid>

</phone:PhoneApplicationPage>

我不能使用列表框或类似的东西,因为在我的应用程序中,图像并不能很好地排列起来

有什么建议吗? 谢谢
Tomas使图像不可见并不能阻止它被解码成未压缩的形式,这需要大量内存,特别是如果它很大的话


您将需要一种更有效的“虚拟化”图像的方法,在图像不可见时完全卸载图像。这就是LongListSelector能给你的。ScrollViewer不会这样做。

即使图像的可见性设置为“折叠”时会占用空间,但与实际显示图像时ScrollViewer会吃的东西相比,这是微不足道的。即使我用一个空白矩形替换并丢弃了应用程序中的所有图像,它仍然会很快耗尽内存。