2013-02-06 31 views
2

我有一个类,这里​​是它的XAML部分侧:XAML中的引用是否会导致内存泄漏?

<Grid x:Class="KETAB.KStudio.Stage.KPage" Name="Scaller" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
    xmlns:model="clr-namespace:KETAB.KStudio.Models;assembly=KETAB.KStudio.Models" 
    xmlns:p="clr-namespace:KETAB.KStudio.Stage" 
     Cursor="None" 
    xmlns:Header_Footer="clr-namespace:KETAB.KStudio.Stage.Header_Footer" AllowDrop="True" Width="{Binding Path=Width}" Height="{Binding Path=Height}" > 
    <Grid.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="/KETAB.KStudio.Stage;component/Resources/StageResources.xaml"/> 
       <ResourceDictionary Source="/KETAB.KStudio.UserControls;component/SharedDictionaryGreen.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Grid.Resources> 
<!--"{Binding ElementName=PagesList, Path=ScaleX}"--> 
    <Grid.LayoutTransform> 
     <ScaleTransform ScaleX="{Binding ElementName=PagesList, Path=ScaleX}" 
             ScaleY="{Binding ElementName=PagesList, Path=ScaleY}" 
         ></ScaleTransform> 
    </Grid.LayoutTransform> 

    <!--Width="{Binding Path=Width}" Height="{Binding Path=Height}"--> 
    <aero:SystemDropShadowChrome Name="ShadowChrome" Opacity="0.75" Margin="0,0,-5,-5" /> 
    <!--Width="{Binding Path=Width}" Height="{Binding Path=Height}"--> 
    <Border BorderBrush="{StaticResource dark}" BorderThickness="1.5" Name="PageBorder" > 
     <!--Width="{Binding Path=WidthViewModel , RelativeSource={RelativeSource AncestorType={x:Type model:Page_ViewModel}}}" Height="{Binding Path=Height , RelativeSource={RelativeSource AncestorType={x:Type model:Page_ViewModel}}}"--> 

      <Grid Name="Sizer" > 

      <Canvas Name="Layout" Background="{StaticResource light}" ClipToBounds="True" Cursor="None"/> 

      <Canvas Name="ImportedImageLayer" Background="Transparent" ClipToBounds="True" Cursor="None"/> 

      <p:InkSurface x:Name="LayerInkSurface" Cursor="None" /> 

      <p:TempSurface x:Name="TempSurface0" Cursor="None" /> 
      <p:TempSurface x:Name="TempSurface1" Cursor="None" /> 



      <p:Surface x:Name="LayerOnTopTools" Cursor="None" > 

      </p:Surface> 


      <p:Surface x:Name="DraggingSurface0" Cursor="None" /> 
      <p:Surface x:Name="DraggingSurface1" Cursor="None" /> 

      <Header_Footer:HeaderFooterView x:Name="MyHeaderView" VerticalAlignment="Top" PictureVerticalAlignment="Top" MyVerticalAlignment="Top" /> 
      <Header_Footer:HeaderFooterView x:Name="MyFooterView" VerticalAlignment="Bottom" PictureVerticalAlignment="Bottom" MyVerticalAlignment="Bottom" /> 

      <Canvas Name="GridsCanvas" ClipToBounds="True" IsHitTestVisible="False"> 

      </Canvas> 

      <p:TopViewLayer x:Name="PageTopView" ClipToBounds="True" /> 


     </Grid> 

    </Border> 

</Grid> 

的代码背后有一个Dispose方法,这将部署在XAML提及的情形:

public void Dispose() 
{ 
LayerInkSurface.Dispose(); 
LayerOnTopTools.Dispose(); 
TempSurface0.Dispose(); 
TempSurface1.Dispose(); 

DraggingSurface0.Dispose(); 
DraggingSurface1.Dispose(); 
} 

但是,当我做内存分析,我发现负责内存泄漏的根路径是:

DraggingSurface0 
DraggingSurface1 
LayerOnTopTools 

这是因为我没有使它们无效?应该这样做:

DraggingSurface0= null; 
DraggingSurface1= null; 
LayerOnTopTools= null; 

处置它们后?这真的很重要吗?

+0

也许相关:http://stackoverflow.com/questions/502761/disposing-wpf-user-controls? – Jocke

回答

相关问题