我在程序中使用了CList
具体定义如下:
class CGUIInfo : public CObject
{
public:
CGUIInfo() {}
virtual ~CGUIInfo() 
{
m_Info.RemoveAll();
};
CString m_strGUIName;
CStringList m_Info;
};typedef CTypedPtrList<CObList, CGUIInfo*> CGUIInfoList;class CMAPInformation
{
public:
CMAPInformation() {}
virtual ~CMAPInformation() 
{
m_GUIInfo.RemoveAll();
};
    CString  m_strAppName;

    CGUIInfoList m_GUIInfo;
};CMAPInformation m_test;
当程序退出后出现
Detected memory leaks!
Dumping objects ->
改怎么做才能不出现泄漏?

解决方案 »

  1.   

    if(FileDlg.DoModal() == IDOK)
    {
    m_GUIMapInfo.m_GUIInfo.RemoveAll();
    m_ctrListGUIName.ResetContent();
    m_strMapName = FileDlg.GetPathName();
    CString strTitle;
    GetWindowText(strTitle);
    SetWindowText(strTitle + " - " + m_strMapName);
    CStdioFile file;   // file
    CFileException ex; // file unexception
    CString strtemp;
    CString strtemp1;
    int lFlag = 0; // 0 or 1
    CGUIInfo* m_GUITemp;

    // open gui file.
            if((file.Open(m_strMapName, CFile::modeRead, &ex)) == 0)
            {
                MessageBox("Unexception Error!", 
                    "GUI变换", MB_ICONINFORMATION);
                return;
            }
    while (file.ReadString(strtemp)) 
    {
    if (strtemp.GetLength() == 0) {
    continue;
    }
    if (strtemp.Find(ID_APP_NAME, 0) != -1) 
    {
    strtemp1 = strtemp.Mid(strlen(ID_APP_NAME),
    strtemp.GetLength());
    m_GUIMapInfo.m_strAppName = strtemp1;
    }
    else if (strtemp.Find(ID_GUI_NAME, 0) != -1 
         || lFlag == 1) 
    {
    // get 试验画面名
    if (lFlag == 0) {
    m_GUITemp = new CGUIInfo();
    strtemp1 = strtemp.Mid(strlen(ID_GUI_NAME),
    strtemp.GetLength());
    m_GUITemp->m_strGUIName = strtemp1;
    lFlag = 1;
    continue;
    } // get GUI 控件信息
    if (lFlag == 1) 
    {
    if (strtemp == "#") 
    {
    m_GUIMapInfo.m_GUIInfo.AddTail(m_GUITemp);
    //delete m_GUITemp;
    lFlag = 0;
    continue;
    }
    m_GUITemp->m_Info.AddTail(strtemp);
    }
    }
    }
    }
    程序中打开文件,然后将文件内容存储到CList中,当我关闭程序后出现内容泄漏