ADO Memory usage - leak?
-
Hi. I've got a basic ADO AddNew call, running in a loop, against Access 2002. Running on VC++6, Win2K, MDAC 6 sp2. See code below. It seems to use memory constantly, even when the recordset object is released. It uses approx 10MB per 100,000 rows written. My system needs to be on line and writing data for a week at a time so this is going to be a problem for me. Any ideas? Ta. Gizz. The following function is called from another big loop... void fn() { using namespace ADODB; _RecordsetPtr pRst = NULL; _ConnectionPtr pConnection = NULL; _bstr_t strCnn("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\data.MDB"); try { TESTHR(pConnection.CreateInstance(__uuidof(Connection))); pConnection->Open(strCnn,"","",adConnectUnspecified); TESTHR(pRst.CreateInstance(__uuidof(Recordset))); pRst->Open("tblMyTable",_variant_t((IDispatch *) pConnection, true), adOpenKeyset,adLockOptimistic,adCmdTable); _variant_t strGBID("GBID"); _variant_t strTSID("TimestampID"); static long i = 0; static long imax = 1000; for (;i < imax; i++) { pRst->AddNew(); {_variant_t vtFld; vtFld.vt = VT_I4; vtFld.lVal = i; pRst->Fields->GetItem(strGBID)->Value = vtFld;} {_variant_t vtFld; vtFld.vt = VT_I4; vtFld.lVal = i+1; pRst->Fields->GetItem(strTSID)->Value = vtFld;} pRst->Update(); } imax += 1000; pRst->Close(); pConnection->Close(); pConnection.Release(); pRst.Release(); } catch(_com_error &) {} }
-
Hi. I've got a basic ADO AddNew call, running in a loop, against Access 2002. Running on VC++6, Win2K, MDAC 6 sp2. See code below. It seems to use memory constantly, even when the recordset object is released. It uses approx 10MB per 100,000 rows written. My system needs to be on line and writing data for a week at a time so this is going to be a problem for me. Any ideas? Ta. Gizz. The following function is called from another big loop... void fn() { using namespace ADODB; _RecordsetPtr pRst = NULL; _ConnectionPtr pConnection = NULL; _bstr_t strCnn("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\data.MDB"); try { TESTHR(pConnection.CreateInstance(__uuidof(Connection))); pConnection->Open(strCnn,"","",adConnectUnspecified); TESTHR(pRst.CreateInstance(__uuidof(Recordset))); pRst->Open("tblMyTable",_variant_t((IDispatch *) pConnection, true), adOpenKeyset,adLockOptimistic,adCmdTable); _variant_t strGBID("GBID"); _variant_t strTSID("TimestampID"); static long i = 0; static long imax = 1000; for (;i < imax; i++) { pRst->AddNew(); {_variant_t vtFld; vtFld.vt = VT_I4; vtFld.lVal = i; pRst->Fields->GetItem(strGBID)->Value = vtFld;} {_variant_t vtFld; vtFld.vt = VT_I4; vtFld.lVal = i+1; pRst->Fields->GetItem(strTSID)->Value = vtFld;} pRst->Update(); } imax += 1000; pRst->Close(); pConnection->Close(); pConnection.Release(); pRst.Release(); } catch(_com_error &) {} }
I don't know where is the problem,But about
pConnection.Release();
andpRst.Release();
I have to say you don't need them because you use these inrefaces as an pointer and they will release automaticlly. But you problem MAYBE because of access,I know it has limitation on number of records,and after you insert 100,000 rows in a table in crash or ....You didn't which line cause memory leak! Mazy "And the carpet needs a haircut, and the spotlight looks like a prison break And the telephone's out of cigarettes, and the balcony is on the make And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits