This is a migrated thread and some comments may be shown as answers.

Memory Cleanup/Leak

9 Answers 576 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Tim Rohrer
Top achievements
Rank 1
Tim Rohrer asked on 26 Apr 2010, 02:24 PM
I have been having issues with what appear to be memory leaks when using Telerik WinControls. I first noticed the issue in a form that we have that has dozens of controls on it, and which increases the memory usage by upwards of 40 MB when shown. However, I then made a new project, simply dragged a few controls onto the form, and I am seeing the exact same issue, just on a smaller scale. When the application first starts, memory usage is around 18 MB, but by the time it is done, usage is around 40 MB. The code that I am running the test with is:

Public Class Main
    Shared Sub Main()
        MessageBox.Show("Start")

        For i = 0 To 50 Step 1
            Dim f As New Form1
            f.Show()
            Threading.Thread.Sleep(100)
            f.Close()
            f.Dispose()
        Next

        GC.Collect()
        MessageBox.Show("Stop")
    End Sub
End Class

The controls that I used the designer to add to the form are:
    Friend WithEvents RadMenu1 As Telerik.WinControls.UI.RadMenu
    Friend WithEvents RadButton1 As Telerik.WinControls.UI.RadButton
    Friend WithEvents RadTextBox1 As Telerik.WinControls.UI.RadTextBox
    Friend WithEvents RadSplitButton1 As Telerik.WinControls.UI.RadSplitButton
    Friend WithEvents RadCarousel1 As Telerik.WinControls.UI.RadCarousel
    Friend WithEvents RadButton2 As Telerik.WinControls.UI.RadButton

What am I doing wrong? Using some memory profiling tools, it looks like there may be timers still running or other event handlers registered that are preventing the controls from being garbage collected.

Is there something special that needs to be done to clean up after the Telerik controls?

Due to the size of the form we are using in real life, this can quickly cause the application to be using 100's of MB's of memory, which has actually led to out-of-memory issues in some cases.

Thanks for your help!

9 Answers, 1 is accepted

Sort by
0
Vassil Petev
Telerik team
answered on 27 Apr 2010, 09:59 AM
Hi Tim Rohrer,

Could you share the RadControls version you have tested this with?
 
Thanks.

 
All the best,
Vassil
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tim Rohrer
Top achievements
Rank 1
answered on 27 Apr 2010, 03:03 PM
I have tested this using two different RadControls versions: 2010.1.10.409 and 8.2.0.0. I saw the same behavior with both versions.

I am developing in Visual Studio 2008 using VB.net.
0
Deyan
Telerik team
answered on 03 May 2010, 04:19 PM
Hi Tim,

Thanks for getting back to us and for the provided details.

We have performed a simple test based on the code snippet that you sent us. What we did was create a RadForm and put the described controls on it. After that, using a for-loop we instanciated, showed and disposed of the form 1000 times which caused the memory to jump from 16MB to approximately 35-40MB. At the point when the memory consumption reaches 40MB, the GC of the .NET runtime launched and collected the unused memory causing the footprint to go back to 25 - 30 MB.

This is a normal behavior for RadControls for WinForms and it is due to the internal infrastructure of our framework that supports the theming mechanism, the dependency property system etc. In general, when you create a RadControl its default theme is deserialized and registered in the ThemeResolutionService, its dependency properties are created, initialized and registered in the property store which reflects on the memory footprint. These resources are static and are alive as long as your application runs.

I hope this helps.

Do not hesitate to write back anytime you have further questions or need assistance.
 

All the best,
Deyan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Lakshmi
Top achievements
Rank 1
answered on 11 Sep 2013, 09:14 AM
Dear Telerik Team,
I am using Latest telerik version 2013.2.612.20.
One form is verg heavy in my application in terms of it has at the max 700 contols combination of labels,MCCb,checkbox,radiobutton,textbox,splicontainers,toolwindows,raddock,buuton.
When the form is opened , the memeory is increaaed40-50MB.This is only one time openeing of the form.Imagine the same form opens by several users means what will happen to the Terminal servers(where we are creating instances for the users to access the project).

Questions is:
1.Is that any other way, that can reduce the memeory.
2.I am not using any theme resolution in the controls only themeclass is using like
Public Sub New()
       MyBase.New()
       Me.ThemeClassName = "Telerik.WinControls.UI.RadCheckBox"
       Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
   End Sub


Thanks Lakshmi
0
Dimitar
Telerik team
answered on 16 Sep 2013, 10:36 AM
Hi Lakshmi,

Thank you for writing.

A memory footprint of 30-40 MB is normal for a form with that many controls. I would like to clarify that the .NET Garbage Collector is non-deterministic and you cannot say for sure when and how memory will be released. 

I can suggest only general things for the memory optimization like: you have to dispose all dynamically created disposable objects explicitly. This includes the Form and all UserControls, including the child UserControls.

I am not sure that is related to your application, but when you display a form as a modal dialog using the ShowDialog method, it is not automatically disposed when you close it. This is the default behavior of the WinForms dialogs and they function this way because the ShowDialog method blocks the control flow of the program and in the general case you will need to use this form at a later stage. 

This approach is also suggested for non modal forms, you should call its Dispose method when you are done working with it:
RadForm form = new RadForm();
form.Show();
//do something with form
form.Dispose();
This is necessary because as I mentioned the .NET garbage collector is non-deterministic.

I hope you will find this useful.

Regards,
Dimitar
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Lakshmi
Top achievements
Rank 1
answered on 16 Sep 2013, 11:22 AM
Hej Dimitar,

sorry it is not 40 mb,form has 700 controls memeory and it  is 250mb every time when the form is loading.

Thanks
Lakshmi
0
Dimitar
Telerik team
answered on 18 Sep 2013, 02:54 PM
Hello Tim,

Thank you for writing back.

.Net do not have a clear way to determine the exact memory usage that complex forms have. The memory usage depends on the number of the controls used and their complexity. For example RadGridView uses more memory than RadListControl. It also depends on the data context. A RadGridView control bound to a DataTable containing 400 000 records will consume 140 Mb of memory.

Also there is at least one theme that is loaded all the time and is consuming 20 MB. We constantly try to improve the memory consumption of our controls, but all themes, animations and the rich functionality that we offer comes at its price. Unfortunately there is nothing else that I can advise you for reducing the memory footprint.

I hope that you find this information useful.
 
Regards,
Dimitar
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Lakshmi
Top achievements
Rank 1
answered on 20 Sep 2013, 09:22 AM

Dear Dimitar,

Thanks for the mail.
But still I am unsure with the answer.
1.I have my own usercontrol of every telerik controls like Labels,MCBBS.(This is because I have set of properties and handlers to be done in once)
2.Event time when form is loading , it will enter into the Usercontrol New() method.
3.It occupies 100- 300kb memery for every control irrespective of Labels,Mccbs,textbox.
4.When the form is open again and again, memory is very high, eventhough I disposed all the controls,forms.....
5.Let me know, is it because I am having Usercontrols or natuarlly when we are using drag and drop of Telrik controls.?
6.Please guide me, why memory consumption is high for my application.

Public Sub New()
        MyBase.New()
 
        AddHandler Me.KeyPress, AddressOf PcsMultiColumnComboBox_KeyPress
 
        AddHandler Me.LostFocus, AddressOf PcsMccb_Lostfocus
        AddHandler Me.TextChanged, AddressOf PcsMccb_TextChanged
        AddHandler Me.SelectedIndexChanged, AddressOf PcsMccb_Lostfocus
        AddHandler Me.Leave, AddressOf PcsMccb_Lostfocus
        AddHandler Me.MultiColumnPopupForm.PopupClosing, AddressOf Firing_PopupClosing
 
        Me.EditorControl.MultiSelect = True
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
        Me.Size = New System.Drawing.Size(100, 18)
        
       
    End Sub
0
Dimitar
Telerik team
answered on 24 Sep 2013, 02:27 PM
Hello Lakshmi,

Thank you for writing back.

I want to ask you to specify the type and the number of the controls that you are using. With this information I will test the memory consumption on my end one more time in order to ensure that this is the normal consumption on both sides. In the meantime I want to suggest you to test your solution with memory profiling tool (for example JustTrace). Please note that when testing for memory leaks you should call the garbage collector before checking the memory: 
GC.Collect()
GC.WaitForPendingFinalizers()
GC.WaitForFullGCApproach()
GC.WaitForFullGCComplete()
GC.Collect()

I hope this information helps. I am looking forward to your reply.

Regards,
Dimitar
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Tim Rohrer
Top achievements
Rank 1
Answers by
Vassil Petev
Telerik team
Tim Rohrer
Top achievements
Rank 1
Deyan
Telerik team
Lakshmi
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or