This code creates a memory leak:
If I delete shape after this code then it messes up my shapes array (CArray <CShape *, CShape *>). I do delete the shapes array when the program closes.Code:CShape *shape = new CShape();
shape->m_sName = newShape.m_sShapeName;
shape->m_sPoints = newShape.m_sShapePoints;
shape->m_nSides = newShape.m_nSides;
shapes->Add(shape);
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
pFrame->m_TreeView->AddShapeToTree(shape);
What am I doing wrong?
Bit more info. Here's where I create the array:
And here's deleting it:Code:shapes = new CArray<CShape *, CShape *>();
I am missing something obvious. Why do I still get a memory leak?Code:for (int x = 0; x < theApp.shapes->GetCount(); x++)
delete theApp.shapes->GetAt(x);
theApp.shapes->RemoveAll();

