Wednesday, August 20, 2008

ShowDialog Memory leak in WinForm

Recently we had to use a common form to display all the reports for a windows application. For some reason all the reports would work only once. We were using a ReportForm.ShowDialog() to show the report form. Apparently ShowDialog doesn’t dispose the form when its closed as a normal form does when its shown using Form.Visible = True. After a lot of search I came across the article which mentioned that there is a memory leak issue if you don’t dispose the form properly after ShowDialog.

Best Practice according to the article is open the form using the following code and it works, solved our issue.

Quote:

using( SomeDialog sd = new SomeDialog() )
{
sd.ShowDialog();
}

Link:

http://kevin-berridge.blogspot.com/2007_08_01_archive.html

No comments: