我似乎在基于Angular的应用程序中发生了内存泄漏,我一直在查看并将其缩减到此测试用例:http://plnkr.co/edit/JIt8PrV28lKnlSx8I8xP?p=preview。
基本上,归结为我不知道如何从文档中干净地删除ng-repeat。如果我使用 <Style TargetType="{x:Type ListView}">
<Setter Property="Background" Value="Green"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListView}">
<Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true">
<ScrollViewer Padding="{TemplateBinding Padding}" Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</Microsoft_Windows_Themes:ListBoxChrome>
<ControlTemplate.Triggers>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<!-- Here comes your custom disabled background color -->
<Setter Property="Background" TargetName="Bd"
Value="Red"/>
<!-- Here comes your custom disabled background color -->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
表格已从文档中删除,但缓存的侦听器(例如jQuery().remove()
)会导致泄漏。
我现在有一个$watchCollectionAction()
电话,我想在示例中清理,但这不是答案......
谢谢!
答案 0 :(得分:0)
如果超时功能
,则plunkr示例有效setTimeout( function () {
vm.persons = [];
$scope.$apply();
}, 1000 );
由于您从Angular机制外部进行了更改,因此需要$apply
(请参阅https://docs.angularjs.org/api/ng/type/ $ rootScope.Scope#$ apply)。