AUTHOR: Georgi Georgiev
DATE MODIFIED : February 26, 2017
DATE POSTED: November 14, 2014
Your application consumes more memory when it has RadControls and some of the memory is not immediately or is never disposed.
The increased memory usage might come from the fact that our controls provide rich UI capabilities and theming mechanism. 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 the standard controls which simply wrap native objects.
When the first RadControl for an application is created it also loads its theme. Loading the theme consists of parsing a number of XML files and creating objects from that files. Since recreating these objects every time a control needs a theme is not efficient they are being saved for the lifetime of the application. These objects will not be disposed unless the application is closed.
However, there are cases when the memory will continue to raise over time. This case happen, for example when you open and close new Forms/RadForms with RadControls inside multiple times. Closing or calling the Dispose method of the form will NOT actually dispose the objects immediately. They will simply be marked for disposal and the next time the Garbage Collector passes by it will decide whether they are suitable for 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).
Moreover, even if the Task Manager shows a certain amount of memory usage that does not necessarily mean that your application is actually using this amount of memory. Since taking memory from the Operating System is an expensive operation .NET tries to keep the memory for the application for as long as possible, for example until another application needs this memory. When inspecting your application for memory leaks with the Task Manager, always look at the private working set of the process. It shows the memory which cannot be used by another process. For example, on the image below you can see that Visual Studio is actually using 1,126,508 K of memory while its working set is 1,461,308:
When showing forms using the ShowDialog method make sure to dispose them manually. Here is a quite from MSDN:
Unlike non-modal 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 hidden instead of closed, you must call the Dispose method of the form when the form is no longer needed by your application.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.