我試圖在我們的應用程序中控制內存。但內存與新應用程序啓動時不一樣。窗口電話中的內存泄漏7
實施例:
在應用程序,我有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>
第1頁:當我從記憶恢復的MainPage,我的應用程序從1Mb增加至超過5Mb的。
在頁面1的列表框中,我添加一個圖像到列表框,當我回頁面時,我將圖像控件設置爲空URL並且imageControl = null;內存不減少
任何人都可以指向正確的方向嗎?
問題不明,請重新配製。我有這樣的感覺,即當控件返回到主頁面時,您預期與page1相關的所有內存都會被釋放。即使忘記了應用程序邏輯(沒有顯示,也可能包含對您的擔憂的解釋),但不能在不運行GC的情況下對內存作任何聲明(因爲對象完成時間不確定)。 –
看起來像一個笨蛋http://stackoverflow.com/questions/7023879/how-does-one-release-cache-of-application-in-windows-phone-7。 –