Problem : Deleting CToolTipCtrl Dynamic Memory
Hi, in my dialog app I am using CToolTipCtrl to implement some tooltip text in various places, yet despite using “delete” in my class destructor, VC++ keeps telling me this is causing memory leaks.
In the header file of my main dialog class I have declared my pointer as follows:
CToolTipCtrl *m_ToolTip;
Then in my OnInitDialog function I do the following:
TCHAR message[500];
m_ToolTip = new CToolTipCtrl();
m_ToolTip->Create(this);
_stprintf (message, “Select a machine for further details”);
m_ToolTip->AddTool(&m_machine_list_ctrl, message);
I use these last two lines several times further to put different messages on different controls.
Then in my class destructor I delete the memory as follows:
delete m_ToolTip;
Upon investigation it appears as though the more times I call AddTool, the greater the memory leak. What is the proper way to delete this dynamic memory?
Solution: Deleting CToolTipCtrl Dynamic Memory
Forget about the deleting each tooltip you add (I think that is a red herring, mainly because I don’t need it for cleaning up tooltips that I create in a similar way.).
Give this a quick try.
Instead of
CToolTipCtrl *m_ToolTip;
use
CToolTipCtrl m_ToolTip;
In the OnInitDialog
TCHAR message[500];
m_ToolTip.Create(this);
_stprintf (message, “Select a machine for further details”);
m_ToolTip.AddTool(&m_machine_list_ctrl, message);
and do not use the delete m_ToolTip in your destructor.
Also how are you creating/destroying the dialog – I think the problem with your code could be there.