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

Memory Leak after disposing a dialog?

1 Answer 645 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Christian asked on 03 Oct 2014, 04:35 PM

( Please if I'm wrong with my understanding of this rectify me )

Reading about good and bad programming practices I heared that when calling a ShowDialog method (at least in a normal Windows.Form) that Form is not disposed after the DialogResult is sent, the Form remain in memory so it will be disposed manually, well, then following that good practices that is was I'm trying to do with a RadForm, this is the code:

If ConfigureCorner.ShowDialog() = Windows.Forms.DialogResult.OK Then
                                           "Action applied",
End If

The problem is that every time that I call ShowDialog after the Form is disposed for first time the memory increases like 5-10 mb each time, and it needs much execution time to display the Form and its controls.

I attached an image to show the Form contents, but his is the detailed content of the RadForm:

· 3 different themes

· 15 RadButtons
· 5 RadCheckBoxes
· 1 RadDropDownList
· 8 RadGroupBoxes
· 21 RadLabels
· 1 RadPageView
· 12 RadPageViewPages
· 2 RadRadioButtons
· 12 RadSeparators
· 8 RadTextBoxControls

· 2 Custom dialogs for open folder/files.

As you see seems that I'm not using anything special that should 'cause this memory leak,
the images of the controls are set directlly in the designer property grid as 'Image' property,
I'm not loading or instancing any disposable object before closing the RadForm.

Also, I'm trying to force garbage collecting aftear each call to Dispose method after calling ShowDialog, but that does not solve anything:


This is normal?

Any information will be very appreciated, thanks in advance.

1 Answer, 1 is accepted

Sort by
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Oct 2014, 10:09 AM
Hello Christian,

Thank you for writing.

The memory leak is caused by the fact that you are showing a new Form instance every time with the ShowDialog method. A quote from MSDN says: "Unlike modeless forms, the Close method is not called by the .NET Framework when the user clicks the close form button of a dialog box or sets the value of the DialogResult property. Instead the form is hidden and can be shown again without creating a new instance of the dialog box. Because a form displayed as a dialog box is not closed, you must call the Dispose method of the form when the form is no longer needed by your application." You can refer to ShowDialog Dispose Memory Leak MSDN forum post which is quite useful about this topic.

I would like to let you know that our controls provide rich UI capabilities and theming mechanism which inevitably increases the memory usage. Furthermore our components are built from the Telerik Presentation Framework which is built on top of the .NET Framework which once again, inevitably increases memory usage compared to other controls, such as the standard controls which simply wrap native objects. Unless a certain control has a memory leak it is eventually being disposed. Calling GC.Collect will not dispose the objects immediately, they will simply be marked for disposal and the next time the Garbage Collector passes it will decide whether they are suitable for actual disposal. This is due to the non-deterministic behavior of the Garbage Collector. Our objects are mostly from Generation 3, which means that they will be disposed at a later state (more about garbage collection). 

I hope this information helps. Should you have further questions, I would be glad to help.


Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Asked by
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question