在网上下载了一个ADO封装类,是成真写的.(大家应该知道吧)
m_adoConnection.BeginTrans();m_adoRecordSet.Open("SELECT * FROM DZSZ ORDER BY 时间");
int nCount = m_adoRecordSet.GetRecordCount(); //查找记录个数//时间的准备,时间存储方式为字符串
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
CString csTime;
csTime.Format("%04d-%02d-%02d %02d:%02d:%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay,
sysTime.wHour,sysTime.wMinute,sysTime.wSecond);CString csSQL; //查询
if (nCount >= NNUMSOFRECORD) //高于指定条目
{
//查询出时间最小的
m_adoRecordSet.MoveFirst();
CString csOldTime;
m_adoRecordSet.GetCollect("时间",csOldTime);

//更新数据(最早的记录)
csSQL.Format("UPDATE DZSZ SET 时间 = '%s',f1 = %.1f,f2 = %.1f,f3 = %.1f,f4 = %.1f,f5 = %.1f WHERE 时间 = '%s'",
csTime, g_Info.m_fDataBuf[0],g_Info.m_fDataBuf[1],g_Info.m_fDataBuf[2],g_Info.m_fDataBuf[3], g_Info.m_fDataBuf[4],csOldTime);
m_adoRecordSet.Open(csSQL);
}
m_adoConnection.CommitTrans();
每隔1秒钟执行上面代码一次.执行了12个小时,发现内存多出2M的样子, 是不是内存泄漏啊?(其他地方不会产生内存泄漏的)
还有数据库文件也大了2M左右啊???不知道为什么啊? 一直是更新的啊如果谁有OLE DB封装好的类提供的话,也照样给分~~~~~

解决方案 »

  1.   

    为什么记录集只有打开,没有关闭呢?在DEBUG下,调式,按F5键,然后运行此段代码一段时间,在关闭,如果有内存泄漏,在开发工具的输出栏中,有内存泄露的提示信息的
      

  2.   

    Detected memory leaks!
    Dumping objects ->
    f:\程序开发\nestshark\nestshark\mainfrm.cpp(122) : {259} normal block at 0x01600068, 40000 bytes long.
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
    Object dump complete.
    程序“[328] NestShark.exe: 本机”已退出,返回值为 0 (0x0)。
    -----------------------------------------------------------
    如果是类似这种,就是有内存泄漏了,f:\程序开发\nestshark\nestshark\mainfrm.cpp(122)      指出内存泄漏的地方
      

  3.   

    的确是有内存泄漏,但没有提示哪里泄漏啊!!高手帮忙分析下
    Dumping objects ->
    {1911} normal block at 0x0037DCE0, 256 bytes long.
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
    {1910} normal block at 0x0037DB98, 256 bytes long.
     Data: <   "            > 00 02 17 22 00 00 03 E8 00 00 00 00 00 00 00 00 
    {1868} normal block at 0x0037CF68, 256 bytes long.
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
    {1867} normal block at 0x0037CE20, 256 bytes long.
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
    {1866} normal block at 0x0037CCD8, 256 bytes long.
     Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
    {1865} The thread 0x15EC has exited with code 0 (0x0).
    normal block at 0x0037C890, 1024 bytes long.
     Data: <  7   7 h 7     > D8 CC 37 00 20 CE 37 00 68 CF 37 00 CD CD CD CD 
    {1864} normal block at 0x0037C748, 256 bytes long.
     Data: <   "            > 00 02 16 22 00 00 00 00 00 00 00 00 00 00 00 00 
    {1863} normal block at 0x0037C600, 256 bytes long.
     Data: <   "            > 00 02 17 22 00 00 03 E8 00 00 00 00 00 00 00 00 
    {1862} normal block at 0x0037C4B8, 256 bytes long.
     Data: <   "            > 00 02 17 22 00 00 03 E8 00 00 00 00 00 00 00 00 
    {1861} normal block at 0x0037C370, 256 bytes long.
     Data: <   "            > 00 02 16 22 00 00 00 00 00 00 00 00 00 00 00 00 
    {1860} normal block at 0x0037C228, 256 bytes long.
     Data: <   "            > 00 02 16 22 00 00 00 00 00 00 00 00 00 00 00 00 
    {1859} normal block at 0x0037BDE0, 1024 bytes long.