I have a winform application which has a dynamic number (based on a database value) of PictureBoxes
. Each P-Box has a Tooltip
control.
How can I change the ToolTip Text without having any memory leaks? Right now, I've got the following code, but it's leaking memory => the previous ToolTip controls are not getting GC'd.
BTW, this is a background thread that is trying to update the main UI thread....
if (pictureBox == null || !pictureBox.IsHandleCreated) {
continue;
}
Action setTooltipAndImage = () => {
var toolTip = new ToolTip();
GameServer tempGameFile = gameServer;
toolTip.SetToolTip(pictureBox, string.Format(...));
pictureBox.Image = Resources.RedButton;
};
if (pictureBox.InvokeRequired) {
pictureBox.Invoke(setTooltipAndImage);
} else {
setTooltipAndImage();
}
As I said - this works but it's leaking.
Anyone have any suggestions?