Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

visual state dynamicresource storyboard memory leak on ResourceReferenceExpression+ResourceReferenceExpressionWeakContainer

$
0
0

Recently, I found that using dynamicresource of storyboard for visualstate's storyboard will cause memory leak. To find the details I used both ANTS Memory Profiler and Telerik JustTrace.

The problem is shown as below.

In Xaml,

    <Storyboard x:Key="AM_MEDIA_NORMAL" >
        <ui:LinearGradientBrushAnimation To="{StaticResource LINEAR_Back_Media_Normal}"  Storyboard.TargetProperty="(Background)" Duration="00:00:00.12"/>
    </Storyboard>
    <Storyboard x:Key="AM_MEDIA_OVER" >
        <ui:LinearGradientBrushAnimation To="{StaticResource LINEAR_Back_Media_Over}"  Storyboard.TargetProperty="(Background)" Duration="00:00:00.12"/>
    </Storyboard>
    <Storyboard x:Key="AM_MEDIA_SELECTED" >
        <ui:LinearGradientBrushAnimation To="{StaticResource LINEAR_Back_Media_Selected}"  Storyboard.TargetProperty="(Background)" Duration="00:00:00.12"/>
    </Storyboard>

then in other xaml, an ItemContainerStyle applied to a listview

        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="ui:ListViewItem">
                    <Setter Property="SnapsToDevicePixels" Value="True"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ui:ListViewItem">
                                <Border Name="PART_CONTENT" Background="{StaticResource LINEAR_Back_Media_Normal}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                                    <GridViewRowPresenter VerticalAlignment="Center" />
                                    <VisualStateManager.CustomVisualStateManager>
                                        <ui:AdvancedVisualStateManager/>
                                    </VisualStateManager.CustomVisualStateManager>
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup >
                                           <VisualState Name="Normal" Storyboard.TargetName="PART_CONTENT" Storyboard="{DynamicResource AM_MEDIA_NORMAL}"/>
                                           <VisualState Name="MouseOver" Storyboard.TargetName="PART_CONTENT" Storyboard="{DynamicResource AM_MEDIA_OVER}"/>
                                           <VisualState Name="Selected" Storyboard.TargetName="PART_CONTENT" Storyboard="{DynamicResource AM_MEDIA_SELECTED}"/>
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>

Using dynamicresource of storyboard so that I can switch animations in runtime by unloading the previous xaml and loading another xaml (both of them have "AM_MEDIA_NORMAL", "AM_MEDIA_OVER" and "AM_MEDIA_SELECTED" ) for change the visualstate's storyboard.

DynamicResource of Storyboards worked very well but when listview create new item, it will create new listviewitem and create new visualstates. However, the internal class "ResourceReferenceExpression+ResourceReferenceExpressionWeakContainer" will not be finalized.

Is it a bug or the storyboard can not be dynamically binding to the visualstate's storyboard?

Any suggestion?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>