DocumentRuler Memory Leak

4 posts, 0 answers
  1. Ryan
    Ryan avatar
    7 posts
    Member since:
    Sep 2012

    Posted 03 Apr 2013 Link to this post

    There appears to be a memory leak when a DocumentRuler is associated to a RadRichTextBox.  The following is code for a demo WPF Application project that can demonstrate this issue:

    MainWindow.Xaml:
    <Window x:Class="RulerMemoryLeakDemo.MainWindow"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="25"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>       
            <StackPanel Grid.Row="0" Orientation="Horizontal">
                <Button Click="ButtonBase_OnClick">New Editor</Button>
            </StackPanel>
            <StackPanel Grid.Row="1" Name="editHost"></StackPanel>
        </Grid>
    </Window>

    MainWindow.xaml.cs:
    using System.ComponentModel;
    using System.Windows;
     
    namespace RulerMemoryLeakDemo
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public class EditorViewModel : INotifyPropertyChanged
            {
                private string _rtf = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
    {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\f0\fs22 RTF File - Hello World\par
    }";
                public string Rtf
                {
                    get { return _rtf; }
                    set
                    {
                        _rtf = value;
                        OnPropertyChanged("Rtf");
                    }
                }
     
                public event PropertyChangedEventHandler PropertyChanged;
     
                protected virtual void OnPropertyChanged(string propertyName)
                {
                    var handler = PropertyChanged;
                    if (handler != null)
                        handler(this, new PropertyChangedEventArgs(propertyName));
                }
            }
     
            public MainWindow()
            {
                InitializeComponent();
            }
     
            private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
            {
                editHost.Children.Clear();
                var viewModel = new EditorViewModel();
                var view = new EditorView {DataContext = viewModel};
                editHost.Children.Add(view);           
            }
        }
    }

    EditorView.xaml:
    <UserControl
        x:Class="RulerMemoryLeakDemo.EditorView"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="1000"
        FontFamily="Arial" FontSize="11">   
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>   
            <telerik:DocumentRuler Grid.Row="0" AssociatedRichTextBox="{Binding ElementName=editor, Mode=OneTime}"/>
            <telerik:RadRichTextBox x:Name="editor"     
                                    Margin="24 24 0 0"
                                    Grid.Row="0"
                                    LayoutMode="Flow"/>
            <telerik:RtfDataProvider x:Name="rtfProvider"                                 
                                     RichTextBox="{Binding ElementName=editor}"
                                     Rtf="{Binding Path=Rtf, Mode=TwoWay}"  />
        </Grid>
    </UserControl>

    EditorView.xaml.cs:
    using System.Windows.Controls;
    namespace RulerMemoryLeakDemo
    {
        public partial class EditorView : UserControl
        {
            public EditorView()
            {
                InitializeComponent();         
            }
        }
    }


    The demo app has a button "New Editor" which will create a new usercontrol with a RadRichTextBox and associated DocumentRuler and add it to the main window.  If you keep pressing the New Editor button you will see that the memory usage of the application keeps growing.  Repeatedly creating new editors on my desktop caused the application memory usage to grow to over 4GB.

    However, in EditorView.xaml, if you comment out the DocumentRuler declaration and repeat the test you will find that the memory usage of the application no longer grows unbound.  On my desktop the memory usage of the application after commenting out this line stayed under 400MB.

    My desktop is running Win 7 x64, though this problem was observed on a number of different systems.
  2. Boby
    Admin
    Boby avatar
    595 posts

    Posted 04 Apr 2013 Link to this post

    Hi Ryan,
    Can you confirm that the version you are using is 2013.1.220, as we were not able to reproduce the leak with the latest version, nor with 2013.1.220?
    Do you have any observations of the types that are leaking?

    Regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Ryan
    Ryan avatar
    7 posts
    Member since:
    Sep 2012

    Posted 11 Apr 2013 Link to this post

    I just tried again with the recent 2013.1.403 release, and I am still able to reproduce this leak.  The following is top items from a heap dump of a test app this is occurring on with over 1GB in memory usage:

    000007fe939ebab8    10140       730080 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Double, mscorlib]], mscorlib],[Telerik.Windows.Documents.Model.Styles.TableProperties, Telerik.Windows.Documents]]
    000007fe939e3528     5070       730080 Telerik.Windows.Documents.Model.Styles.TableCellProperties
    000007fef1e84528     9365       749200 System.Reflection.RtFieldInfo
    000007fe93a4d740     5070       770640 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Windows.Media.Color, PresentationCore]], mscorlib],[Telerik.Windows.Documents.Model.Styles.TableCellProperties, Telerik.Windows.Documents]]
    000007fe939ebe88     5070       770640 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Windows.Media.Color, PresentationCore]], mscorlib],[Telerik.Windows.Documents.Model.Styles.TableProperties, Telerik.Windows.Documents]]
    000007fef09b6b60    12062       771968 System.Collections.Specialized.NotifyCollectionChangedEventHandler
    000007fee3c001a0     5552       799488 System.Windows.Data.BindingExpression
    000007fee509d6d8    10206       816480 System.Windows.Media.TranslateTransform
    000007fe93a4a070    15240       853440 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Boolean, mscorlib]], mscorlib],[Telerik.Windows.Documents.Model.Styles.ParagraphProperties, Telerik.Windows.Documents]]
    000007fe93a49bf0    15240       853440 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Int32, mscorlib]], mscorlib],[Telerik.Windows.Documents.Model.Styles.ParagraphProperties, Telerik.Windows.Documents]]
    000007fe93a49920    15240       853440 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.String, mscorlib],[Telerik.Windows.Documents.Model.Styles.ParagraphProperties, Telerik.Windows.Documents]]
    000007fee3c102f0     2184       856128 System.Windows.Controls.Primitives.Thumb
    000007fee3c2b168    13440       860160 System.Windows.VisualState
    000007fee509a690    10893       871440 System.Windows.Media.SolidColorBrush
    000007fe93f11e08        1       872496 System.Collections.Generic.Dictionary`2+Entry[[System.String, mscorlib],[System.Double, mscorlib]][]
    000007fee4cce490    21864       874560 System.Collections.Generic.List`1[[System.Windows.Media.Animation.ObjectKeyFrame, PresentationCore]]
    000007fee3c21750    10089       887832 MS.Internal.Data.PropertyPathWorker
    000007fe939e0038    15961       893816 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[Telerik.Windows.Documents.UI.TextDecorations.DecorationProviders.IUnderlineUIDecorationProvider, Telerik.Windows.Documents],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe939cf8b8    15961       893816 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Boolean, mscorlib]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe939cedc8    15961       893816 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Windows.FlowDirection, PresentationCore]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe939ce148    15961       893816 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[Telerik.Windows.Documents.Model.BaselineAlignment, Telerik.Windows.Documents]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe939cb0b8    15961       893816 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Windows.FontWeight, PresentationCore]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe939ca438    15961       893816 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Windows.FontStyle, PresentationCore]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe939c97b8    15961       893816 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[Telerik.Windows.Documents.Model.Themes.ThemeFontsEnum, Telerik.Windows.Documents]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe939c8810    15961       893816 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Windows.Media.FontFamily, PresentationCore],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fef1e0fc48     8876       923104 System.Reflection.RuntimePropertyInfo
    000007fee3c06aa0    14802       947328 System.Windows.Media.Animation.Storyboard
    000007fe939e3230     5070      1014000 Telerik.Windows.Documents.Model.Styles.TableProperties
    000007fee509bde0     4202      1042096 System.Windows.Media.Animation.AnimationClock
    000007fe939cbba8    15961      1149192 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Double, mscorlib]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe93a49370     7620      1158240 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Windows.Media.Color, PresentationCore]], mscorlib],[Telerik.Windows.Documents.Model.Styles.ParagraphProperties, Telerik.Windows.Documents]]
    000007fee5099328    14795      1183600 System.Windows.Media.Animation.TimelineCollection
    000007fee8b845b0     9476      1212928 MS.Internal.Xaml.Context.ObjectWriterFrame
    000007fe939e7830    38806      1241792 Telerik.Windows.Documents.Model.Styles.RadStylePropertyCollection
    000007fee3c1b650    23720      1365984 MS.Internal.Data.SourceValueInfo[]
    000007fee58a2870    21850      1398400 System.Windows.Media.Animation.DiscreteObjectKeyFrame
    000007fee3c06be0    23719      1518016 System.Windows.PropertyPath
    000007fe939e78c0    38806      1552240 System.Collections.Generic.List`1[[Telerik.Windows.Documents.Model.Styles.IStylePropertyDefinition, Telerik.Windows.Documents]]
    000007fee58a7430    21850      1573200 System.Windows.Media.Animation.ObjectKeyFrameCollection
    000007fee3bfedd8     3362      1586864 System.Windows.Controls.TextBlock
    000007fef0d8e858    41264      1650560 System.Collections.Specialized.HybridDictionary
    000007fe93ad5e10     9333      1714344 System.Collections.Generic.HashSet`1+Slot[[Telerik.Windows.Documents.Model.BibliographicReferences.BibliographicReferencePropertyDefinition, Telerik.Windows.Documents]][]
    000007fe939ccfc8    31922      1787632 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[Telerik.Windows.Documents.Model.Themes.ThemeColorsEnum, Telerik.Windows.Documents]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fef1e1c0f0     5069      1819392 System.Collections.Hashtable+bucket[]
    000007fe9399f130     7830      1879200 Telerik.Windows.Documents.Model.Styles.StyleDefinition
    000007fe939e2d68     7620      1889760 Telerik.Windows.Documents.Model.Styles.ParagraphProperties
    000007fef0d8e730    40034      1921632 System.Collections.Specialized.ListDictionary
    000007fee58a7360    21850      1922800 System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames
    000007feec286b50    40756      1956288 System.Windows.ModifiedValue
    000007fef1e18b48    90508      2172192 System.WeakReference
    000007fee50be8c0    23112      2403648 System.Windows.Media.RenderData
    000007fee3bfbc00     8064      2903040 System.Windows.Controls.Canvas
    000007fee3c1a6c8     7562      3024800 System.Windows.Controls.Grid
    000007fef0d8fa08    77571      3102840 System.Collections.Specialized.ListDictionary+DictionaryNode
    000007fe93a48390    45720      3291840 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Double, mscorlib]], mscorlib],[Telerik.Windows.Documents.Model.Styles.ParagraphProperties, Telerik.Windows.Documents]]
    000007fef1e31210   141347      3392328 System.Double
    000007fee3c1edc8     9912      3409728 System.Windows.Shapes.Path
    000007fe939cd618    63844      3575264 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.String, mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fe939c7630    15961      3575264 Telerik.Windows.Documents.Model.Styles.SpanProperties
    000007fef1e204d0    25727      4144522 System.Byte[]
    000007fee3bf5f00    13105      4508120 System.Windows.Controls.Border
    000007fef1e24138    79008      5056512 System.EventHandler
    000007fef1e136c8    45828      5132736 System.Reflection.RuntimeMethodInfo
    000007fee3c1a370    18132      6817632 System.Windows.Shapes.Rectangle
    000007fe939cc328    47883      7278216 Telerik.Windows.Documents.Model.Styles.StyleProperty`2[[System.Nullable`1[[System.Windows.Media.Color, PresentationCore]], mscorlib],[Telerik.Windows.Documents.Model.Styles.SpanProperties, Telerik.Windows.Documents]]
    000007fef1e1c358   118277      9389984 System.String
    000007feec285f08   198825     27456632 System.Windows.EffectiveValueEntry[]
    000007fef1e00630   203912     49623736 System.Object[]
    0000000000a0a940    18437     52079750      Free
    000007fef1e1f0a8    24488    102915584 System.Int32[]
    000007fe93f14ee8      336    608283648 System.Collections.Generic.Dictionary`2+Entry[[System.String, mscorlib],[System.Collections.Generic.List`1[[System.String, mscorlib]], mscorlib]][]
  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 16 Apr 2013 Link to this post

    Hello,
    We are still not able to reproduce the leak. Note that for realistic results, you should call the garbage collector before tracking the memory:
    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();

    Don't hesitate to contact us if you have other questions.


    Regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top