使用
#define _CRTDBG_MAP_ALLOC
#include<stdlib.h>
#include<crtdbg.h>
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );_CrtDumpMemoryLeaks();
检测到程序有内存泄露问题,不知道问题出在哪,恳请各位高手指点!谢谢
Detected memory leaks!
Dumping objects ->
strcore.cpp(118) : {85} normal block at 0x005210F0, 45 bytes long.
Data: < 6 > 01 00 00 00 01 00 00 00 20 00 00 00 36 00 CD CD
strcore.cpp(118) : {84} normal block at 0x00521150, 57 bytes long.
Data: < , , sele> 01 00 00 00 2C 00 00 00 2C 00 00 00 73 65 6C 65
strcore.cpp(118) : {83} normal block at 0x005211C0, 23 bytes long.
Data: < 2006> 01 00 00 00 0A 00 00 00 0A 00 00 00 32 30 30 36
strcore.cpp(118) : {82} normal block at 0x00521210, 23 bytes long.
Data: < 2006> 01 00 00 00 0A 00 00 00 0A 00 00 00 32 30 30 36
strcore.cpp(118) : {81} normal block at 0x00521260, 23 bytes long.
Data: < 2006> 01 00 00 00 0A 00 00 00 0A 00 00 00 32 30 30 36
strcore.cpp(118) : {80} normal block at 0x00521A50, 15 bytes long.
Data: < ma > 01 00 00 00 02 00 00 00 02 00 00 00 6D 61 00
{51} client block at 0x00521D50, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521D50, 64 bytes long
{46} client block at 0x00521E90, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521E90, 64 bytes long
{44} client block at 0x00521FB0, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521FB0, 64 bytes long
Object dump complete.
#define _CRTDBG_MAP_ALLOC
#include<stdlib.h>
#include<crtdbg.h>
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );_CrtDumpMemoryLeaks();
检测到程序有内存泄露问题,不知道问题出在哪,恳请各位高手指点!谢谢
Detected memory leaks!
Dumping objects ->
strcore.cpp(118) : {85} normal block at 0x005210F0, 45 bytes long.
Data: < 6 > 01 00 00 00 01 00 00 00 20 00 00 00 36 00 CD CD
strcore.cpp(118) : {84} normal block at 0x00521150, 57 bytes long.
Data: < , , sele> 01 00 00 00 2C 00 00 00 2C 00 00 00 73 65 6C 65
strcore.cpp(118) : {83} normal block at 0x005211C0, 23 bytes long.
Data: < 2006> 01 00 00 00 0A 00 00 00 0A 00 00 00 32 30 30 36
strcore.cpp(118) : {82} normal block at 0x00521210, 23 bytes long.
Data: < 2006> 01 00 00 00 0A 00 00 00 0A 00 00 00 32 30 30 36
strcore.cpp(118) : {81} normal block at 0x00521260, 23 bytes long.
Data: < 2006> 01 00 00 00 0A 00 00 00 0A 00 00 00 32 30 30 36
strcore.cpp(118) : {80} normal block at 0x00521A50, 15 bytes long.
Data: < ma > 01 00 00 00 02 00 00 00 02 00 00 00 6D 61 00
{51} client block at 0x00521D50, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521D50, 64 bytes long
{46} client block at 0x00521E90, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521E90, 64 bytes long
{44} client block at 0x00521FB0, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521FB0, 64 bytes long
Object dump complete.
UpdateData();
Cmysqldb sqltest; //定义类
int i; //临时变量
unsigned __int64 numrecords;//查询返回的记录数
CString strTemp;
CString sqlstr,m_date,m_sdate,m_edate;
m_date=m_Date.Format("%Y-%m-%d");
m_sdate=m_StartDate.Format("%Y-%m-%d");
m_edate=m_EndDate.Format("%Y-%m-%d");if(Flag==1)
sqlstr.Format("select * from eventlog where logwebname='%s'",m_Proxy);
if(Flag==2)
sqlstr.Format("select * from eventlog where logdate>='%s'",m_date);
if(Flag==3)
sqlstr.Format("select * from eventlog where logdate>='%s' and logdate<='%s'",m_sdate,m_edate);char *sql=(LPTSTR)(LPCTSTR)sqlstr;//char* sql="select * from eventlog where logdate >='2006-06-06'";
m_ListCtrl.DeleteAllItems(); //清除显示的数据
if(sqltest.ConnectDB())//连接数据库
{
if(!sqltest.Executesql(sql, 1)) //执行SQL语句,flag为1表示查询,要返回结果集
{
MessageBox(sqltest.geterrormessage(),"错误提示",MB_OK+MB_ICONINFORMATION);//显示错误信息
}
else
{
numrecords=sqltest.GetRowNum();//得到数据记录的数目
if(numrecords==0)
MessageBox("数据库中无相关信息!","提示",MB_OK+MB_ICONINFORMATION);
for(i=0;i<numrecords;i++)
{
if (sqltest.GetRecord()) //判断是否已经到数据集合的尾部
{
strTemp.Format("%d",i+1);
m_ListCtrl.InsertItem(i,strTemp);
m_ListCtrl.SetItemText(i,1,sqltest.row[1]);
m_ListCtrl.SetItemText(i,2,sqltest.row[2]);
m_ListCtrl.SetItemText(i,3,sqltest.row[3]);
m_ListCtrl.SetItemText(i,4,sqltest.row[4]);
m_ListCtrl.SetItemText(i,5,sqltest.row[5]);
}
}
sqltest.FreeRecord();//释放数据集合的内存空间
_CrtDumpMemoryLeaks();
}}
else
{
MessageBox(sqltest.geterrormessage(),"错误提示",MB_OK+MB_ICONINFORMATION);
}
Detected memory leaks!
Dumping objects ->
{51} client block at 0x00521D50, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521D50, 64 bytes long
{46} client block at 0x00521E90, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521E90, 64 bytes long
{44} client block at 0x00521FB0, subtype 0, 64 bytes long.
a CDynLinkLibrary object at $00521FB0, 64 bytes long
Object dump complete.
有资料说这是MFC的BUG,对于用MFC自动生成的工程也存在内存泄露问题,不知道有没有办法解决?如果不管报告提示,对程序最后的使用会不会导致大问题?
int _tmain(int argc, _TCHAR* argv[])
{
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF |
_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_CHECK_CRT_DF |
_CRTDBG_LEAK_CHECK_DF );
_CrtCheckMemory();
return 0;
}
可以看到,VC2005的库里自己就有mem leak