2011-08-26 71 views
1

我試圖在我們的應用程序中控制內存。但內存與新應用程序啓動時不一樣。窗口電話中的內存泄漏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;內存不減少

任何人都可以指向正確的方向嗎?

+2

問題不明,請重新配製。我有這樣的感覺,即當控件返回到主頁面時,您預期與page1相關的所有內存都會被釋放。即使忘記了應用程序邏輯(沒有顯示,也可能包含對您的擔憂的解釋),但不能在不運行GC的情況下對內存作任何聲明(因爲對象完成時間不確定)。 –

+0

看起來像一個笨蛋http://stackoverflow.com/questions/7023879/how-does-one-release-cache-of-application-in-windows-phone-7。 –

回答

2

見的釋放在http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx

如何圖像存儲器指令您確認內存是從圖像,而不是其他任何你正在使用,可能不清理?

+0

我想在我的應用程序中釋放內存泄漏。當我回頁面時,內存不會減少。馬特萊西,請幫助我:D – thongaduka

+0

馬特萊西!如何在代碼後面更新服務引用? – thongaduka

+0

有關內存管理的一般技巧,我建議在新工具RC中使用分析器來識別問題。請參閱http://msdn.microsoft.com/en-us/library/hh202934(v=vs.92).aspx –