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:
MainWindow.xaml.cs:
EditorView.xaml:
EditorView.xaml.cs:
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.
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
xmlns:telerik=
"http://schemas.telerik.com/2008/xaml/presentation"
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.