【问题标题】:Memory usage of ScrollViewer in Windows Phone 8Windows Phone 8 中 ScrollViewer 的内存使用情况
【发布时间】:2013-03-29 15:19:55
【问题描述】:

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

例如,下面的 XAML 会占用 300 MB 中的 125 MB,而这只是空白的白色画布。

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

我不能使用列表框或类似的东西,因为图像在我的应用中并没有很好地排列。

有什么建议吗? 谢谢! 托马斯

【问题讨论】:

    标签: xaml memory windows-phone-8


    【解决方案1】:

    使图像不可见并不会阻止它被解码为未压缩的形式,这会占用大量内存,尤其是在它很大的情况下。

    您将需要一种更有效的“虚拟化”图像的方法,以便在图像不在视野范围内时完全卸载它们。这就是 LongListSelector 可以给你的。 ScrollViewer 不这样做。

    【讨论】:

    • 即使图像在其可见性设置为折叠时会占用空间,但与实际显示它们时 ScrollViewer 将吃掉的内容相比,这只是花生。即使我用一个空白矩形替换并丢弃了我的应用程序中的每个图像,它仍然会很快耗尽内存。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多