Memory leaks with IsContentPreserved and remove from MVVM-binded ItemSource

5 posts, 0 answers
  1. Aleksey
    Aleksey avatar
    13 posts
    Member since:
    Nov 2012

    Posted 14 May 2014 Link to this post

    Have TabControl
    <telerik:RadTabControl Name="TabControl" IsContentPreserved="True"  ItemsSource="{Binding Workspaces}" SelectedItem="{Binding CurrentWorkspace, Mode=TwoWay}">
    ItemsSource in binding using MVVM to ObservableCollection<ViewBase>.
    Program dynamically add tabs in it and remove it. When tab is removed, memory is leak, because there is a link to ViewBase class from some dictionary. There is also TabItem in memory but not in TabControl.Items.
    If IsContentPreserved="False" there is no leak.
    If defined empty ContentTemplate for TabControl there is no memory leak.
    <telerik:RadTabControl.ContentTemplate>
        <DataTemplate>
        </DataTemplate>
    </telerik:RadTabControl.ContentTemplate>
  2. Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 15 May 2014 Link to this post

    Hello Aleksey,

    We have tried to reproduce the memory leak that you have reported, but with no success. We used JustTrace to profile the application and it did not report any remaining RadTabItems after the test. I attached the project we used for the test, if you cant reproduce the issue could you please modify the project and send it back to us. Also I would like to ask you to tell us the profiler tool you used.

    Looking forward to hearing from you.

    Regards,
    Kiril Vandov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
  4. Aleksey
    Aleksey avatar
    13 posts
    Member since:
    Nov 2012

    Posted 16 May 2014 Link to this post

    Thanks for answer!
    Cannot reproduce it with small example. Maybe it is depends of content.
    <telerik:RadGridView
                         Grid.Row="1"
                         Style="{StaticResource RadGridViewStyle}"
                         ItemsSource="{Binding Items}"
                         SelectedItem="{Binding CurrentItem, Mode=TwoWay}"
                         Name="MyName">
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Width="200" Header="IsNotInclude" DataMemberBinding="{Binding IsNotInclude}" MinWidth="100" CellStyle="{StaticResource centerCellStyle}"/>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    RadGridViewStyle it is default style for grid defined in app.xaml. centerCellStyle is default style for bool columns.
    <Style x:Key="RadGridViewStyle" TargetType="telerik:RadGridView">
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Visible"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Visible"/>
        <Setter Property="ShowGroupPanel" Value="False"/>
        <Setter Property="SelectionMode" Value="Single"/>
        <Setter Property="AutoGenerateColumns" Value="False"/>
        <Setter Property="IsReadOnly" Value="True"/>
        <Setter Property="RowIndicatorVisibility" Value="Collapsed"/>
    </Style>
     
    <Style TargetType="telerik:GridViewCell" x:Key="centerCellStyle">
        <Setter Property="VerticalContentAlignment"  Value="Center" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
    </Style>

    PS. I'm using Telerik 2012.3.1017.1050 because of this http://www.telerik.com/forums/styleselector-null-return-bug and may be other new features (not comletly tested).
  5. Aleksey
    Aleksey avatar
    13 posts
    Member since:
    Nov 2012

    Posted 17 May 2014 Link to this post

    Work about this memory leaks found three memory leaks problems:
    1) Last screenshot probably is bug ""Memory leak when an application resource is applied to a column dependency property" due to some problems when RadGridView is hosted in RadTabControl" that was fixed in 2013Q1. Not tested because i'm still at 2012Q3.
    2) I'm used RelayCommand with potential memory leak (RefreshCanExecute "strong" event). Google "RelayCommand memory leak MVVM"
    3) Using MyMultiSelectBehavior http://www.telerik.com/forums/multiselect-binding-in-radgridview in TabControl cause memory leak too. Replacing CollectionChangedHandler to weak CollectionChangedHandler with WeakReference fix it.
  6. Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 20 May 2014 Link to this post

    Hello Aleksey,

    We tried to reproduce the issue with the code-snippet you provided but with no success. That is why I would like to ask you to create a sample application reproducing the issue and send it back to us. We need to reproduce the issue on our side in order to investigate the cause of the leak.

    Looking forward to hearing from you.

    Regards,
    Kiril Vandov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
DevCraft banner