Reputation: 501
Setting tooltip on a winform control is like adding something to a dictionary:
ToolTip tt = new ToolTip();
tt.SetToolTip(control, "tooltip text");
Setting the text of a control to null will make the application not to display tooltip on control anymore:
tt.SetToolTip(control, null);
tt must be holding a reference to control. I would like to be sure that removing (and disposing) control won't cause memory leak so I need to remove reference of control from tooltip. Does setting to null remove the reference? Or will tt hold control in its 'dictionary' with null value? In the latter case how to remove this one control for good? (I know tt.RemoveAll() but I need to keep the other tooltips.)
Upvotes: 0
Views: 1113
Reputation: 6852
You can take a look at the source code for Tooltip.SetToolTip
,
look here for SetToolTipInternal
tools
is a Hashtable and passing null does call tools.Remove(control)
:
...
bool exists = false;
bool empty = false;
if (tools.ContainsKey(control)) {
exists = true;
}
if (info == null || String.IsNullOrEmpty(info.Caption)) {
empty = true;
}
if (exists && empty) {
tools.Remove(control);
}
...
Upvotes: 1