我有一个类,这是它的 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;
处理完之后?这真的很重要吗?