Is it possible that when calling multiple times this function:
void Func(String spr, PictureBox pictureBox)
{
ToolTip toolTip = new ToolTip();
toolTip.Show(spr, pictureBox, 1000);
}
memory leak will occur?
After function is finished tooltip is still there is it even possible that it is just going out of scope and disposing itself?
If the answer is “yes” for the first question, is creating my own toolTip which is self disposing from timer_tick a good solution?
public partial class MyToolTip : ToolTip
{
public MyToolTip()
{
InitializeComponent();
timer.Interval = this.AutomaticDelay;
}
private void timer_Tick(object sender, EventArgs e)
{
this.Dispose();
}
}
If in this case this is not necessary is it applicable in other cases when time of object life is known or is it just bad design?
I’ve chosen this solution because i want to be able to show many tooltips at the same time.
The
ToolTipobject will still exist in memory after the method has executed and each time the method is called a newToolTipinstance is created. It’s better to reuse an existingToolTip. e.g.edit For multiple tooltips and to dispose explicitly (outside the GC) without the need for a custom object, you could try something (somewhat hacky 😉 ) like:
The above will work, although, perhaps it would be better to reuse a timer.