Member_2_207537
asked on
Dynamically creating an array of structures
Hi all
Win 95; VC 5.0 SP3
I am trying to create an array dynamically. this sort of works but I am
having trouble with memory leaks when destrying the array. any ideas.
CScaleThread ** ScThread;
in OnInitialUpdate()
{
....
if (pDoc->iNumScales)
{
ScThread = new CScaleThread *[pDoc->iNumScales];
}
for (int y = 0; y < pDoc->iNumScales; y++)
{
ScThread[y] = 0;
}
....
for (int x =0; x < pDoc->iNumScales; x++)
{
GetDialogSize(&R);
ScThread[x] = new CScaleThread;
ScThread[x]->CreateThread( CREATE_SUS PENDED);
// Other stuff here
ScThread[x]->ResumeThread( );
}
...
}
In OnDestroy()
{
CTestscrollDoc* pDoc = GetDocument();
if (ScThread)
{
for (int x =0; x < pDoc->iNumScales; x++)
{
if (ScThread[x])
delete ScThread[x];
}
delete [] ScThread;
}
ScThread = 0;
}
This leaves me with a whole host of memory leaks. Why?
Win 95; VC 5.0 SP3
I am trying to create an array dynamically. this sort of works but I am
having trouble with memory leaks when destrying the array. any ideas.
CScaleThread ** ScThread;
in OnInitialUpdate()
{
....
if (pDoc->iNumScales)
{
ScThread = new CScaleThread *[pDoc->iNumScales];
}
for (int y = 0; y < pDoc->iNumScales; y++)
{
ScThread[y] = 0;
}
....
for (int x =0; x < pDoc->iNumScales; x++)
{
GetDialogSize(&R);
ScThread[x] = new CScaleThread;
ScThread[x]->CreateThread(
// Other stuff here
ScThread[x]->ResumeThread(
}
...
}
In OnDestroy()
{
CTestscrollDoc* pDoc = GetDocument();
if (ScThread)
{
for (int x =0; x < pDoc->iNumScales; x++)
{
if (ScThread[x])
delete ScThread[x];
}
delete [] ScThread;
}
ScThread = 0;
}
This leaves me with a whole host of memory leaks. Why?
ASKER
Hi Dan
Thank you for your input. By commenting you "took the blinkers" off my thinking. I found that the memory leak is comming from a "tested and working" portion of the code.
Though you did not answer the question directly (because the answer lay beyound the question asked) your invaluble comment helped be find the problem. Should you want the points, please replay with an answer indicating so. If not comment as such and I can delete the question.
Many thanks
Hylton
Thank you for your input. By commenting you "took the blinkers" off my thinking. I found that the memory leak is comming from a "tested and working" portion of the code.
Though you did not answer the question directly (because the answer lay beyound the question asked) your invaluble comment helped be find the problem. Should you want the points, please replay with an answer indicating so. If not comment as such and I can delete the question.
Many thanks
Hylton
ASKER
This question has a deletion request Pending
This question no longer is pending deletion
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also make sure that your OnDestroy() is in fact being called and when (put a break point there). If it is not being called, put the delete stuff in the the dtor of the window object or call it from some other point in the program.