Page 1 of 1

ToolTip is leaking memory

Posted: Fri Dec 18, 2009 4:42 pm
by Nalin
While testing my application, i found that System.Window.Forms is leaking memory. So, i just wanted to share this finding in the known memory leaks area.

Its not that dangerous though, but if you have lots of ToolTips on your forms and their tips (messages) are changing dynamically then chances of your application crashing increases.

Microsoft says they fixed it long time back in .Net 2.0. But i can see its still leaking in some cases. In my case, we have a windows base UserControl and inside that a ToolTip was getting created.

Code: Select all

ToolTip newTip = new ToolTip();
newTip.SetToolTip(lblOwner, lblOwner.Text);
I fixed it by adding newTip.RemoveAll() in the Dispose of my UserControl.

Code: Select all

protected override voide Dispose(bool disposing)
{
        //Nalin Bhatia
        newTip.RemoveAll();

        if (disposing && (components != null))
        {
             components.Dispose();
        }
    
         base.Dispose(disposing);
}
[/color]

Any suggestions are welcome.