Memory leak in RadRichTextBox

5 Answers 33 Views
RichTextBox
junaid
Top achievements
Rank 1
Iron
junaid asked on 24 Nov 2022, 02:07 PM

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

Sort by
0
Dimitar
Telerik team
answered on 25 Nov 2022, 11:36 AM

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/.

junaid
Top achievements
Rank 1
Iron
commented on 25 Nov 2022, 11:56 AM

Basically . we have a layout where we make designs maybe we use in layout one radrichtextbox or more. during runtime, I use this layout and change data inside every new job. It takes the data context and updates the layout of richtextbox. so if I am using a single instance for example layout has two rich text boxes after adding the data context in  2nd time it also overrides the data context of the ist element because of the same instance. so that's why every new job I create a new instance but in memory, something remains stuck.  and layout can have multiple elements and is created at runtime and changes context according to data we have at runtime. 
0
junaid
Top achievements
Rank 1
Iron
answered on 25 Nov 2022, 02:58 PM

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

junaid
Top achievements
Rank 1
Iron
commented on 25 Nov 2022, 03:16 PM

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);
            }

                 
0
Dimitar
Telerik team
answered on 28 Nov 2022, 01:48 PM

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/.

0
junaid
Top achievements
Rank 1
Iron
answered on 30 Nov 2022, 08:08 AM

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);

"

Dimitar
Telerik team
commented on 30 Nov 2022, 02:34 PM

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

 

junaid
Top achievements
Rank 1
Iron
commented on 01 Dec 2022, 06:56 AM

but that code is not work for me i try to use that but its not work
Dimitar
Telerik team
commented on 02 Dec 2022, 01:13 PM

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();
}
Let me know if I can assist you further.
0
junaid
Top achievements
Rank 1
Iron
answered on 06 Dec 2022, 07:08 AM

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


Dimitar
Telerik team
commented on 06 Dec 2022, 11:44 AM

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.

Tags
RichTextBox
Asked by
junaid
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
junaid
Top achievements
Rank 1
Iron
Share this question
or