【发布时间】:2011-08-26 16:27:56
【问题描述】:
我试图控制我们应用程序中的内存。但是内存和新应用启动时的内存是不一样的。
例子:
在应用程序中,我有 2 个页面(MainPage.xaml 和 Page1.xaml)。
MainPage(.Xaml) 中的代码:
<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 x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" 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">
<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="147,223,0,0" Name="button1" VerticalAlignment="Top" Width="160"/>
</Grid>
</Grid>
和 Page1.xaml :
<Grid x:Name="LayoutRoot" Background="Transparent">
<Button Content="add" Height="72" HorizontalAlignment="Left" Margin="41,12,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
<Button Content="remove" Height="72" HorizontalAlignment="Left" Margin="240,12,0,0" Name="button2" VerticalAlignment="Top" Width="160" Click="button2_Click" />
<ListBox Height="666" HorizontalAlignment="Left" Margin="12,90,0,0" Name="lsbMyList" VerticalAlignment="Top" Width="456" />
</Grid>
Page1:当我从内存 MainPage 返回时,我的应用程序从 1Mb 增加到超过 5Mb。
在Page1的listbox中,我向listBox添加了一个Image,当我Back Page时,我将图像控件设置为null URL和imageControl = null;内存没有减少
谁能指出我正确的方向?
【问题讨论】:
-
问题不清楚,请重新表述。我感觉您希望在控件返回主页面时释放与 page1 相关的所有内存。即使忘记了应用程序逻辑(未显示并且可能包含对您担心的解释),您也无法在不运行 GC 的情况下对内存做出任何声明(因为对象最终确定的时间是不确定的)。
-
看起来像是 stackoverflow.com/questions/7023879/… 的骗子。
标签: windows-phone-7 windows-phone-7.1