Memory issues with radform, can't seem to dispose added controls

2 posts, 0 answers
  1. Aron
    Aron avatar
    13 posts
    Member since:
    Apr 2015

    Posted 13 May 2015 Link to this post


     What's the proper way to dispose of a radform to ensure that all of the added controls also gets removed? As it is now, each time i start the form and then close it, memory consumption goes up with about 10mb. The core issue here seems to be that even though the form calls .Dispose() when it's closed the controls added to the form does not get cleared. I've tried setting all of the controls in the form to null on close, but this did not have any effect on the memory issue. 

     To make sure that it was an issue with the specific form, i created an empty form and instead opened that one, and when that form closed, memory did not increase, which leads me to be pretty sure that it has something to do with the controls added to the form not getting disposed. 

  2. Dimitar
    Dimitar avatar
    1321 posts

    Posted 13 May 2015 Link to this post

    Hello Aron,

    Thank you for writing.

    Generally the garbage collector is nondeterministic and you cannot tell for sure when the will be executed. This means that even if the form is disposed correctly the memory would not be released right after the form is closed. By default you do not need to dispose the form or the controls manually (unless you are using modal dialog) and the memory will be freed at some point. You can test this properly with a memory profiler tool (JustTrace for example). With this tool you can force the garbage collector and properly determine, if indeed there is a memory leak. More information is available here: Things to keep in mind when inspecting your application's memory usage. 

    In addition you should make sure that there is no references to the form or the controls in it in your code. Even a single reference can prevent the entire form from proper disposal.

    I hope this helps. Should you have any other questions do not hesitate to ask.

    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 Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top