Feel like a geek and get yourself Ema Personal Wiki for Android and Windows

16 December 2008

Memory leak in Tooltip in Usercontrol

Today and yesterday i have been hunting a memory leak in one of our applications. Today i found the leaking line (!) and commented it for now:

' Me.ToolTip1.SetToolTip(Me.Label1, someString)

The cause: a ToolTip in a UserControl will prevent the garbage collector from collecting the usercontrol after a call to Tooltip.SetToolTip. 

This was a known bug with a workaround in .NET 1.x, which seems to have resurrected from .NET 2.0 onwards. The workaround involves explicitly disposing the ToolTip when the form is disposed. But alas! The workaround won't work around when the ToolTip is part of a UserControl who's parentform is not disposed. 

In our case the form will not often be disposed, but the usercontrols are frequently created and destroyed during the lifetime of the form. And since there is no way to tell when a usercontrol is "unloaded", there is no way to apply the workaround.  

The test project can be downloaded from my website



No comments: