内存泄漏:Detected memory leaks
//对话框类,调用CSCItemCount类
void CSCCountDlg::OnOK() //计算功能
{
CSCItemCount scItemCount;
CString strValue;
double dStandCost(0);
try
{
m_pPDMItem = new CPDMObject;
m_pPDMItem->m_pClass = pItemCls;
m_pPDMItem->InitColumnContentList();
m_pPDMItem->m_nObjectID = m_nObjectID;
if( !scItemCount.LoadSubItem(
m_pdmSel.m_nObjectID,m_pPDMItem,pBomCls,perdef1.m_lstFO,m_pChGlobarVar ) )
{
throw 101;
}
dStandCost = scItemCount.m_dStandCost;
}
if( NULL != m_pPDMItem )
delete m_pPDMItem;
}
catch( ... )
{
if( NULL != m_pPDMItem )
delete m_pPDMItem;
return ;
}
m_dStandCost = dStandCost;
UpdateData( false );
}
//CSCItemCount 类,与对话框类不在同一DLL中
BOOL CSCItemCount::LoadSubItem( UINT nObjectID,CPDMObject *pItemObj, CPDMClass *pBomCls,
COptionList &lstFo,CCheckGlobalVar
*pChGlobarVar )
{
COleDateTime tmCurSys;
CString strProduct, strTime;
CPDMResourceMgr mgrResource( _T("pdmcore.dll") );
CAConnect myConnect;
CString strCount;
strProduct= _T("");
//1) 获取服务器当前时间
if( !DLLGetSysCurDate( strTime, tmCurSys ) )
tmCurSys = COleDateTime::GetCurrentTime();
//2) 连接数据库
if ( !CCommFun::ConnectDB( myConnect, m_strServer, m_strDBName, m_strDBUser, m_strDBPwd ) )
return false;
_CONNECT_PDMSERVER_RETURN()
m_pItemObj = pItemObj;
m_pItemObj->m_fQuantityOld = m_pItemObj->m_fQuantity;
//3) BOM展开
if( !this->LoadChildItem( myConnect,session, pItemObj, pItemObj->m_pClass ,pBomCls, m_lstItem,
lstFo, tmCurSys, strProduct , pChGlobarVar ) )
return false;
//计算,根据m_lstItem记录的内容从数据库读取内容
m_lstItem.RemoveAll( );
return true;
}
BOOL CSCItemCount::LoadChildItem ( CAConnect &myConnect,CSession &session,CPDMObject *pItemObj,
CPDMClass *pItemCls,CPDMClass *pBomCls, CObList &lstItem, COptionList &lstFo, COleDateTime tmCurSys,
CString strProduct,CCheckGlobalVar *pChGlobarVar )
{
CPDMObjectList::Position pos;
CSCItemCount *pSubItem = NULL;
CString strMPType,strControl, strStock;
CFieldList lstField;
BOOL bFolder = false;
CItemOperate ItemOperate;
CString strErr;
double dStandCost(0);
double dCost(0);
//1) 获取指定物料的指定信息
ItemOperate.m_pGlobalVar = pChGlobarVar;
if( !ItemOperate.GetItemInfo( session, pItemObj->m_nObjectID, pItemObj->m_pClass->m_strTabName,
strStock, strControl, strMPType, strErr ) )
{
AfxMessageBox( strErr );
return false;
}
//2) 记录BOM展开所得的所有物料对象
this->m_dSCost = 0;
lstItem.AddTail( this );
//3) NN?(是否控制-是否入库)
if( (strControl.CompareNoCase(_T("N")) ==0) && (strStock.CompareNoCase(_T("N")) == 0 ) )
{
//3.1) 获取ITEM的子项列表
GetSubItemPDMObjList( session, pItemObj, pBomCls, strProduct, tmCurSys, lstFo, lstField
);
//3.2) ITEM有子项,逐条获取其子项的子项,m_lstSubPDMObj将在对话框内delete pPDMItem时析构
if( pItemObj->m_lstSubPDMObj.NumItems() != 0 )
{
for( pItemObj->m_lstSubPDMObj.BeginScan( pos ); pos ; pos++ )
{
if( NULL == (*pos ) )
continue;
pSubItem = new CSCItemCount;
pSubItem->m_pItemObj = (*pos );
pSubItem->m_pParItem = pItemObj;
pSubItem->m_pParCount = this;
pSubItem->m_pItemObj->m_fQuantityOld = (pItemObj->m_fQuantityOld) *
((*pos)->m_fQuantity);
this->m_lstSub.AddTail( pSubItem );
if( !pSubItem->LoadChildItem( myConnect,session, (*pos ), pItemCls,
pBomCls, lstItem, lstFo, tmCurSys, strProduct,pChGlobarVar ) )
return false;
}
}
}
return true;
}
//析构函数
CSCItemCount::~CSCItemCount()
{
m_anID.RemoveAll();
DetachSubList();
}
void CSCItemCount::DetachSubList()
{
CSCItemCount *pItem =NULL;
POSITION pos;
for ( pos = m_lstSub.GetTailPosition(); pos; )
{
pItem = (CSCItemCount*)m_lstSub.GetPrev( pos );
if ( NULL != pItem )
{
delete pItem;
pItem = NULL;
}
}
m_lstSub.RemoveAll();
}
如上过程,我认为所有我new出的对象最后都delete了,但为什么程序正常结束后,会有大量的提示如下:
Detected memory leaks!
Dumping objects ->
{24158} normal block at 0x0B3D1EC8, 20 bytes long.
Data: < = m \ = > 00 00 00 00 F8 1D 3D 0B C4 6D F6 08 5C 1E 3D 0B
strcore.cpp(118) : {24157} normal block at 0x0B3D1E50, 45 bytes long.
Data: < 2930> 01 00 00 00 06 00 00 00 20 00 00 00 32 39 33 30
{24156} normal block at 0x0B3D1DF8, 20 bytes long.
Data: < = ( = g = > C8 1E 3D 0B 28 1D 3D 0B 8C 67 F6 08 8C 1D 3D 0B
strcore.cpp(118) : {24155} normal block at 0x0B3D1D80, 45 bytes long.
Data: < > 01 00 00 00 00 00 00 00 20 00 00 00 00 20 20 20
{24154} normal block at 0x0B3D1D28, 20 bytes long.
Data: < = X = Ta = > F8 1D 3D 0B 58 1C 3D 0B 54 61 F6 08 BC 1C 3D 0B
strcore.cpp(118) : {24153} normal block at 0x0B3D1CB0, 45 bytes long.
Data: < > 01 00 00 00 00 00 00 00 20 00 00 00 00 20 20 20
请高手指教