Re: Memory Leak with Recordset?



> I'm using ADO 2.5 with VC++ trying to release a recordset object from
> memory, however the memory allocated when the recordset was populated
> is not completely freed. Most of it, in fact, remains in memory.
>
> I've read elsewhere (in this ng, post from Feb 1, 1999) that RecordSet
> fields are AddRef'd but not Released, so that the reference count is
> not decremented. A bug in ADO, apparently.

I looked at the Feb 1, 1999 post.
I am uncertain of this. Not all claims are necessarily correct.
I have never seen any confirmed confirmation of this, nor Microsoft
acknowldege this as a Bug and it has to be said ADO gets hammered every day.
In any case, why not use ADO 2.8?

> Even if I close the database connection and delete the class that holds
> the smart pointers for ADO, and call CoUninitialize(), the memory is
> not released until the app is exited.

Yes but this is similar to malloc()/free() & new/delete etc which ultimately
use the heap
When you call free()/delete, they _DO NOT_ release memory to the OS.
Instead the memory is returned to the heap manager within the application,
waiting to be reused again.
Only when the app quits is the memory released. If it was otherwise,
malloc()/free() etc would be unbearably slow, constantly allocating/freeing
memory from the OS. The heap manager is allowing sub-allocation for speed
purposes.
Only if you have something non-standard like _heapshrink() is the memory
really returned to the OS.

I have not studied what COM interfaces ADO uses for managing memory it uses
but I bet it is identical in approach as the heap.

> Interestingly, the memory usage doesn't get any bigger, but it still
> takes a large chunk of memory.

Yup. It is likely to be what I said.

> count = pRS->RecordCount;
> sprintf(bNum,"%ld",count);
> strNum = bNum;
> pRS->Close();
> pRS.Release();

If pRS is a smartpointers, you should not be doing that.
It is enough to do

if ((pRS->State() & (long)ADODB::adStateOpen) != 0)
pRS->Close();
pRS = NULL; // The smartpointer will call Release here

Stephen Howe


.



Relevant Pages

  • Re: Tips on finding memory leaks
    ... But when Access reports that it's using 500M of memory, ... The problem is that at least with Access as the front-end, and ADO in the ... mentioned collections and child objects along with ADO. ... what a Recordset is: "A collection of collections contains objects". ...
    (microsoft.public.vb.general.discussion)
  • Re: Recordset.AddNew and the recordset objects data retaining
    ... via an ADO recordset, then I'd strongly suggest you redesign your solution. ... > to do with the updates being in a transaction but rather on whether you specify ... > spill over and the memory starts paging out to disk that concerns me). ...
    (microsoft.public.data.ado)
  • Re: filter with vb code
    ... I guess ADO classic doesn't interest them. ... There may be no recordset in your post be there certainly is a memory ... SQL involving an open workbook causes a memory leak. ...
    (microsoft.public.excel.programming)
  • Re: Tips on finding memory leaks
    ... Any suggestions, either specific to ADO, collections, or just general to ... As for tracing memory leaks with VB, ... mentioned collections and child objects along with ADO. ... Recordset which can then be wrapped with an object to provide the same ...
    (microsoft.public.vb.general.discussion)
  • Re: ADO - permanent memory leak?!
    ... I have a memory leak in an application that makes repeated ... I have ADO 2.7 ... I am using MemProof 9.5.0 to isolate the problem. ... These are the only "memory growth" items. ...
    (borland.public.delphi.database.ado)