RadGridViewAutomationPeer holding old objects in memory

4 posts, 0 answers
  1. Louis
    Louis avatar
    86 posts
    Member since:
    Aug 2013

    Posted 29 Mar 2017 Link to this post

    What role does RadGridViewAutomationPeer? 

    I have a RadGridView in my application, but when I change my DataContext to a new object containing a new List for the ItemsSource, the RadGridView is still holding all the old objects from the old List used by the ItemsSource in memory through this RadGridViewAutomationPeer. Not knowing what the AutomationPeer does, I'm at a bit of a loss as to how to get it to release those old objects. I wasn't able to find any useful information on this class. I've attached the memory retention chart from dotMemory showing my CurveSets being held.

    Here's the xaml for the chart:

     

    <telerik:RadGridView
        x:Name="CurveList"
        Grid.Row="1"
        AutoGenerateColumns="False" ItemsSource="{Binding Path=Wells}"
        IsFilteringAllowed="False" ShowGroupPanel="False" CanUserSortColumns="False"
        SelectionMode="Single"
        IsSynchronizedWithCurrentItem="True"
        CurrentItem="{Binding Path=DeclineConsolidator.CurrentCurve, Mode=TwoWay}"
        GroupRenderMode="Flat" EnableRowVirtualization="True">
        <telerik:RadGridView.Resources>
            <consolidator:WellNameStyleSelector x:Key="NameStyleSelector">
                <consolidator:WellNameStyleSelector.CleanStyle>
                    <Style TargetType="{x:Type telerik:GridViewCell}">
                        <Setter Property="FontStyle" Value="Normal" />
                    </Style>
                </consolidator:WellNameStyleSelector.CleanStyle>
                <consolidator:WellNameStyleSelector.DirtyStyle>
                    <Style TargetType="{x:Type telerik:GridViewCell}">
                        <Setter Property="FontStyle" Value="Italic" />
                    </Style>
                </consolidator:WellNameStyleSelector.DirtyStyle>
            </consolidator:WellNameStyleSelector>
        </telerik:RadGridView.Resources>
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Header="" Width="25" MaxWidth="25" MinWidth="25" IsReadOnly="True">
                <telerik:GridViewDataColumn.CellTemplate>
                    <DataTemplate>
                        <Image
                            Source="{Binding Source={x:Static pcc:ImageSourceConstants.WarningIcon}}"
                            Visibility="{Binding Path=IsValid, Converter={StaticResource InverseBoolToVisibilityConverter}}"
                            Tag="{Binding Path=ErrorMessageAlert}"
                            Width="15" Height="15" Margin="0,0,0,0">
                            <i:Interaction.Behaviors>
                                <infrastructure:ImageGridValidationBehaviour />
                            </i:Interaction.Behaviors>
                        </Image>
                    </DataTemplate>
                </telerik:GridViewDataColumn.CellTemplate>
            </telerik:GridViewDataColumn>
            <telerik:GridViewDataColumn Header="{x:Static prop:Resources.WellListColumnHeader}"
                                        IsReadOnly="True"
                                        DataMemberBinding="{Binding Path=DisplayName}" Width="*"
                                        CellStyleSelector="{StaticResource NameStyleSelector}" />
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

     

     

  2. Martin
    Admin
    Martin avatar
    160 posts

    Posted 03 Apr 2017 Link to this post

    Hello Louis,

    To stop the memory leak from your application you should disable the creation of the AutomationPeers by setting the AutomationMode property to Disabled.  I must mention that memory leaks due to automation peers are fairly common as they are designed to hold a reference to their UI Element owner, which is why we introduced the option to disable them in the first place. If the Telerik.Windows.Automation.Peers.AutomationManager.AutomationMode property is set to Disabled the AutomationPeer of our controls should be not created. This means that some software that is using them will stop working correctly. This includes any accessibility software like Windows Narrator and Coded UI test recorders.

    Please give this a try and let me know how it works for you.

    Regards,
    Martin Vatev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Louis
    Louis avatar
    86 posts
    Member since:
    Aug 2013

    Posted 04 Apr 2017 in reply to Martin Link to this post

    Hi Martin,

    Turning off AutomationMode indeed solved the problem, thank you!

    Any automation linkages should really be undone when an object is no longer associated with the control it was formerly used by (in this case, removed from the ItemsSource), correct? Is there a way to make this happen grammatically (without turning off all automation), or does this indicate a problem with the framework itself?

    Thanks again,

    Louis

  4. Martin
    Admin
    Martin avatar
    160 posts

    Posted 07 Apr 2017 Link to this post

    Hello Louis,

    Yes, your reasoning is correct, but the issue is connected with the framework itself. To our current understanding, the leak is more of a problem of the framework, as it keeps references to automation peers of controls which are already removed from the visual tree.

    Regards,
    Martin Vatev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top