vc++6.0中内存泄漏请教如何释放
CList<lvItem*, lvItem*> listItems;
POSITION listPos;
//Retrieve the selected items
POSITION pos = pDragList->GetFirstSelectedItemPosition(); //iterator for the CListCtrl
while(pos) //so long as we have a valid POSITION, we keep iterating
{
plvitem = new LVITEM; ZeroMemory(plvitem, sizeof(LVITEM));
pItem = new lvItem; //ZeroMemory(pItem, sizeof(lvItem)); //If you use ZeroMemory on the lvItem struct,
pItem->plvi = plvitem;
pItem->plvi->iItem = m_nDragIndex;
pItem->plvi->mask = LVIF_TEXT;
pItem->plvi->pszText = new char; //since this is a pointer
pItem->plvi->cchTextMax = 255;
m_nDragIndex = pDragList->GetNextSelectedItem(pos);
//Get the item
pItem->plvi->iItem = m_nDragIndex; //
pDragList->GetItem(pItem->plvi); //retrieve the information
CString str1,str2;
str1=pItem->sCol1;
str2=pItem->sCol2;
//Save the pointer to the new item in our CList
listItems.AddTail(pItem);
}
if(pDragList == pDropList) //we are reordering the list (moving)
{
//Delete the selected items
pos = pDragList->GetFirstSelectedItemPosition();
while(pos)
{
} //EO while(pos)
} //EO if(pDragList...
//Iterate through the items stored in memory and add them back into the CListCtrl at the
listPos = listItems.GetHeadPosition();
while(listPos)
{
} //EO while(listPos)
// listItems.RemoveAll();
// for(int i = 1; i < listItems.GetCount(); i ++)
// while(pItem!=NULL)
// {
// }
// while (plvitem!=NULL)
// {
// }
delete plvitem;
delete pItem;
listItems.RemoveAll();
Detected memory leaks!
Dumping objects ->
strcore.cpp(118) : {361} normal block at 0x00385A98, 269 bytes long.
Data: < Line> 01 00 00 00 06 00 00 00 00 01 00 00 4C 69 6E 65
strcore.cpp(118) : {360} normal block at 0x003857F8, 269 bytes long.
Data: < SubL> 01 00 00 00 0B 00 00 00 00 01 00 00 53 75 62 4C
D:\DlgTest_new\DlgTestDlg.cpp(351) : {359} normal block at 0x00384538, 12 bytes long.
Data: < W8 X8 Z8 > 90 57 38 00 04 58 38 00 A4 5A 38 00
D:\DlgTest_new\DlgTestDlg.cpp(349) : {358} normal block at 0x00385790, 40 bytes long.
Data: < > 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
以上用new 分配的内存,我delete 后总是有内存泄漏,请高手指点迷津 谢谢!