0

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.)

Feri
  • 461
  • 4
  • 12
  • Hi you can find your answer here: http://stackoverflow.com/questions/3903878/c-should-object-variables-be-assigned-to-null You shouldn't set the value to null explicitly. Dispose whatever you can dispose and the rest is done by Garbage Collection. – Sebi Nov 14 '16 at 19:38

1 Answers1

1

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);
        }
        ...
KekuSemau
  • 6,830
  • 4
  • 24
  • 34