一个如此简单的ado测试程序居然有内存泄漏,请大虾出手!
Un1 2010-04-21 03:31:35 一天内存使用从8M上升到32M, ado已经更新到最新版本,vc win32 程序全部代码:
#include "stdafx.h"
#include "stdio.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
CoInitialize(NULL);
_ConnectionPtr pConn("ADODB.Connection");
pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"scd.mdb\"", "", "", 0);
MessageBox(NULL, "Start testing", NULL, 0);
long bytes = 1;
long duration = 1;
char ip[16];
strcpy(ip, "1.1.1.1");
long sec = 1;
char path[256];
strcpy(path, "\\path1\\path2");
char id[25];
strcpy(id, "abcdefgh-123456789012345");
char d[20];
while(1){
SYSTEMTIME st;
GetLocalTime(&st);
sprintf(d, "%04d-%02d-%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
char sql[128];
sprintf(sql, "select * from bills where time='%s' and id='%s'", d, id);
try{
_RecordsetPtr rs("ADODB.Recordset");
rs->Open(sql, _variant_t((IDispatch *)pConn, true), adOpenForwardOnly, adLockOptimistic, adCmdText);
if(rs->adoEOF){
rs->AddNew();
rs->PutCollect("time", d);
rs->PutCollect("id", id);
}
rs->PutCollect("bytes", bytes);
rs->PutCollect("duration", duration);
rs->PutCollect("ip", ip);
rs->PutCollect("sec", sec);
rs->PutCollect("path", path);
rs->Update();
rs->Close();
}catch(...){};
Sleep(1000);
FILE *fp = fopen("stop.txt", "rb");
if(fp){
fclose(fp);
break;
}
}
pConn = NULL;
CoUninitialize();
MessageBox(NULL, "App stopped!", NULL, 0);
return 0;
}