I am getting a memory leak problem with Radrichtextbox. I continually create a rich text bus and print. this Radrichtextbox was added to the canvas container then its measured child size and arranged elements every time it went from this procedure it increased huge memory and never goes down, for example, creating 500 Radrichtextbox consumes more than 400 memory. I saw an increase when the parent container try to measure with the specific size and then arrange it and update the layout. I am unable to find which thing retains Radrichtextbox alive in memory. I attached some memory screenshots. i am using telerik version 2021. 1. 119. 45
5 Answers, 1 is accepted
Hello Junaid,
Without having a way to test your scenario I cannot say what is causing the memory leak and if indeed it is caused by the RadRichtextBox. Would it be possible to create a small project that mimics the memory leak and send it to us? This will allow us to properly investigate this case.
In addition, I cannot see a good reason for creating 500 instances. Why not create one and just change the document?
I am looking forward to your reply.
Regards,
Dimitar
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Hi,
I have attached a sample project it's just simple to show you a scenario that we are trying in real. you can choose a default pdf24 printer or anything else which can continue to show documents, not like a Microsoft pdf printer which will ask you for saving documents. just click on the button and then its starts. here I am not changing new data and styles to rad rich text boxes in real we we can visualize multiple rich textboxes in one layout. here one thread continues to create a Radrichtext box and show it in the print dialog.. we have to create every time new instances for radrichtextbox and fill them with text and styles. and it will continue printing maybe 5000 or 10 thousand times. in the sample project, I am not using any specific style and added not much bigger text but it does not free the memory with the passage of time it's increasing. can you provide any solution where memory should go down after every print?
I am looking forward to you. hope so you will provide me some solution for it
further, if you change the code with one click 100 layouts will print. wait for time but the memory is never free. after clicking again an increased shown in the memory
change the work method and add this snippet
for (int i=0; i<=100;i++)
{
TxtFormatProvider provider = new TxtFormatProvider();
var control = new RadRichtextboxcontrol();
control.richtext.Document = provider.Import(dummyText);
control.Width = 500;
control.Height = 1200;
PrintDialog printDlg = new PrintDialog();
printDlg.PrintVisual(control, "Grid Printing.");
control.richtext.Document.Selection.SelectAll();
control.richtext.Document.Delete(false);
}
Hello Junaid,
I was able to reproduce the observed issue. The memory leak is caused by a class in our implementation. I have logged it on our feedback portal. You can track its progress, subscribe to status changes, and add your comment to it here: RichTextBox: Memory leak in RadRichTextBox when executing on a new thread. I have updated your Telerik points.
As a workaround, I can only suggest using the same thread for the printing. If no new thread is used this works as expected.
I want to apologize for the inconvenience this issue is causing you.
Regards,
Dimitar
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Hi, currently I found one solution for it. but I do not confirm how it will work in a parallel multithread environment. for a single STA thread its work. and it stops memory leaks at certain points in time. but your element is heavy and if you need more processing speed you have to work on your element because the dispatcher does not clear the cache. for that, we have to call the dispatcher at the priority of the application's ideal. maybe this will help now but you should find some permanent solution to it
add this snippet at the end or final block
"
Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.SystemIdle, new DispatcherOperationCallback(delegate { return null; }), null);
"
Hi Junaid,
Indeed this is the correct approach. It appears that we have already an item logged for this. I mark the new one as a duplicate. Here is old the item: RichTextBox: Memory leak related to DelayedExecution internal class when editing RadDocument. It contains a slightly different workaround.
Do not hesitate to contact us if you have other questions.
Regards,
Dimitar
Dimitar
Hi Junaid
I have tested this in a memory profiler and this has an effect after the garbage collector is executed (at least 2 times).I have tested the code like this:
private void Workermethod()
{
for (int i = 0; i <= 100; i++)
{
TxtFormatProvider provider = new TxtFormatProvider();
var control = new RadRichtextboxcontrol();
control.richtext.Document = provider.Import(dummyText);
control.Width = 500;
control.Height = 1200;
PrintDialog printDlg = new PrintDialog();
printDlg.PrintVisual(control, "Grid Printing.");
}
Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
Dispatcher.Run();
}

hi,
you share the case for only 100 prints. I added this only for understanding. the worker can have to print 10000 or more unless printing jobs are not completed. The original worker thread work continuously and doesn't stop. in that case, memory continuously increasing
Hi Junaid
You are right, but the issue is the same.
So you can continue to use your workaround until this is resolved?
Let me know if I can assist you further.