Board index » delphi » Memory Leak with ADO/Access

Memory Leak with ADO/Access

I have an app which opens up a form with 7 adodatasets.
One of them is of  "dmFile" commandtype ( I use it as temporary storage).
On opening, the app is taking 6mb memory. After clicking a button,
I run a procedure which opens the 7 adodatasets & does a recursive process.
After that, my app is using up 17mb memory, and when closing the form,
I am still using that 17mb memory (if I reload the form I will be using
more...)
Any idea to help me....? Ah, the recursive call could also be a problem,
but I couldn't find any alternative. It looks like this:

procedure recursiveProc(someparam)

var b: tbookmark;

begin
   dataset1.locate(....someparam...);
   while not dataset1.eof do begin
      ....
      b:=dataset1.getbookmark;
      recursiveproc(someparam);
      dataset1.gotobookmark(b);
      dataset1.freebookmark(b);
      dataset1.next;
   end;
end;

 

Re:Memory Leak with ADO/Access


Why not rewrite the code like this

procedure recursiveProc(someparam)
var b: tbookmark;
begin
   b:=dataset1.getbookmark;  
 Try
   if dataset1.locate(....someparam...) then
   begin
     while not dataset1.eof do
     begin
        ....

        recursiveproc(someparam);
        dataset1.next;
     end;
   end;
 Finally
    dataset1.gotobookmark(b);
    dataset1.freebookmark(b);
 end;
end;
The difference here is, the Bookmark is created/fetched once and freed
once and not many times within a loop and there is no guarantee that it
would always be freed. What if for some odd reason an exception occurs
either a silent one or otherwise. Test the above. The statement if
..Locate(....) is just me assuming you want to check for something
before proceeding.
I would like to know the results using he test routine proposed by me.
HTH

In article <39d0068b_1@dnews>, damian marquez <dmarque...@hotmail.com>
writes

Quote
>I have an app which opens up a form with 7 adodatasets.
>One of them is of  "dmFile" commandtype ( I use it as temporary storage).
>On opening, the app is taking 6mb memory. After clicking a button,
>I run a procedure which opens the 7 adodatasets & does a recursive process.
>After that, my app is using up 17mb memory, and when closing the form,
>I am still using that 17mb memory (if I reload the form I will be using
>more...)
>Any idea to help me....? Ah, the recursive call could also be a problem,
>but I couldn't find any alternative. It looks like this:

>procedure recursiveProc(someparam)

>var b: tbookmark;

>begin
>   dataset1.locate(....someparam...);
>   while not dataset1.eof do begin
>      ....
>      b:=dataset1.getbookmark;
>      recursiveproc(someparam);
>      dataset1.gotobookmark(b);
>      dataset1.freebookmark(b);
>      dataset1.next;
>   end;
>end;

--
Arnold Johnson

Re:Memory Leak with ADO/Access


Thanks, Arnold, I'll definitely look into that, and let you know how it
goes....

Quote
"Arnold Johnson" <Arno...@win-pro.demon.co.uk> wrote in message

news:0tqS7IAI1D05EwpP@win-pro.demon.co.uk...
Quote
> Why not rewrite the code like this

> procedure recursiveProc(someparam)
> var b: tbookmark;
> begin
>    b:=dataset1.getbookmark;
>  Try
>    if dataset1.locate(....someparam...) then
>    begin
>      while not dataset1.eof do
>      begin
>         ....

>         recursiveproc(someparam);
>         dataset1.next;
>      end;
>    end;
>  Finally
>     dataset1.gotobookmark(b);
>     dataset1.freebookmark(b);
>  end;
> end;

> The difference here is, the Bookmark is created/fetched once and freed
> once and not many times within a loop and there is no guarantee that it
> would always be freed. What if for some odd reason an exception occurs
> either a silent one or otherwise. Test the above. The statement if
> ..Locate(....) is just me assuming you want to check for something
> before proceeding.
> I would like to know the results using he test routine proposed by me.
> HTH

> In article <39d0068b_1@dnews>, damian marquez <dmarque...@hotmail.com>
> writes
> >I have an app which opens up a form with 7 adodatasets.
> >One of them is of  "dmFile" commandtype ( I use it as temporary storage).
> >On opening, the app is taking 6mb memory. After clicking a button,
> >I run a procedure which opens the 7 adodatasets & does a recursive
process.
> >After that, my app is using up 17mb memory, and when closing the form,
> >I am still using that 17mb memory (if I reload the form I will be using
> >more...)
> >Any idea to help me....? Ah, the recursive call could also be a problem,
> >but I couldn't find any alternative. It looks like this:

> >procedure recursiveProc(someparam)

> >var b: tbookmark;

> >begin
> >   dataset1.locate(....someparam...);
> >   while not dataset1.eof do begin
> >      ....
> >      b:=dataset1.getbookmark;
> >      recursiveproc(someparam);
> >      dataset1.gotobookmark(b);
> >      dataset1.freebookmark(b);
> >      dataset1.next;
> >   end;
> >end;

> --
> Arnold Johnson

Re:Memory Leak with ADO/Access


Well, the change DID work, and actually it looks much more reliable and
cleaner... Thanks
a lot... but I still have my memory leak problem... I'll post again with a
simple explanation,
since I've found that the recursion would not have anything to do with this
memory loss...

Re:Memory Leak with ADO/Access


Please see my new post: "ADO datasets not freeing lots of memory when
closed"...
The problem is not the recursive function but the ado resources not being
recovered when
the adodatasets are closed (not even after freeing the form)....
any idea about it?
Quote
> What exactly does the function you are calling within the loop actually
> do. Have a second look at it and make sure you are not missing
> something, like creating objects and not freeing them within a
> Try...finally...end construct.

Re:Memory Leak with ADO/Access


What exactly does the function you are calling within the loop actually
do. Have a second look at it and make sure you are not missing
something, like creating objects and not freeing them within a
Try...finally...end construct.

In article <39d13178_2@dnews>, damian marquez <dmarque...@hotmail.com>
writes

Quote
>Well, the change DID work, and actually it looks much more reliable and
>cleaner... Thanks
>a lot... but I still have my memory leak problem... I'll post again with a
>simple explanation,
>since I've found that the recursion would not have anything to do with this
>memory loss...

--
Arnold Johnson

Re:Memory Leak with ADO/Access


We noticed this same problem,  it seems to be with ado (not delphi wrappers)
we were able to reproduce this behavior by using native ado (import ado type
lib), Also found this was true in a vb example just to make sure it was not
delphi specific. What we assume to be happening is that ado manages its own
memory pool and decides when it will reuse the allocated memory and it seems
to vary depending on how much ram you have installed.

The memory is recovered when the application ended just that during the app
the mem usage can go way up... our mdi app was up to 64 meg. we got around
this by sharing / pooling the connection object/s instead of creating a new
one each time we needed it.

rick

Quote
"damian marquez" <dmarque...@hotmail.com> wrote in message

news:39d13991_1@dnews...
Quote
> Please see my new post: "ADO datasets not freeing lots of memory when
> closed"...
> The problem is not the recursive function but the ado resources not being
> recovered when
> the adodatasets are closed (not even after freeing the form)....
> any idea about it?

> > What exactly does the function you are calling within the loop actually
> > do. Have a second look at it and make sure you are not missing
> > something, like creating objects and not freeing them within a
> > Try...finally...end construct.

Re:Memory Leak with ADO/Access


Rick,

Did you need to share or pool the TADODatasets, or was it just enough
to share the TADOConnection?

Chris

On Wed, 27 Sep 2000 23:01:50 -0500, "Rick Jones" <ri...@lconn.com>
wrote:

Quote
>We noticed this same problem,  it seems to be with ado (not delphi wrappers)
>we were able to reproduce this behavior by using native ado (import ado type
>lib), Also found this was true in a vb example just to make sure it was not
>delphi specific. What we assume to be happening is that ado manages its own
>memory pool and decides when it will reuse the allocated memory and it seems
>to vary depending on how much ram you have installed.

>The memory is recovered when the application ended just that during the app
>the mem usage can go way up... our mdi app was up to 64 meg. we got around
>this by sharing / pooling the connection object/s instead of creating a new
>one each time we needed it.

>rick

>"damian marquez" <dmarque...@hotmail.com> wrote in message
>news:39d13991_1@dnews...
>> Please see my new post: "ADO datasets not freeing lots of memory when
>> closed"...
>> The problem is not the recursive function but the ado resources not being
>> recovered when
>> the adodatasets are closed (not even after freeing the form)....
>> any idea about it?

>> > What exactly does the function you are calling within the loop actually
>> > do. Have a second look at it and make sure you are not missing
>> > something, like creating objects and not freeing them within a
>> > Try...finally...end construct.

Chris Miller
VersaTrans Routing and Planning Software
Creighton Manning, Incorporated

Re:Memory Leak with ADO/Access


Quote
>... our mdi app was up to 64 meg. we got around
> this by sharing / pooling the connection object/s instead of creating a
new
> one each time we needed it.

rick, i am not such an advanced programmer... how do you implement that
pooling?
If you talk about adoconnection, I use just one (in a datamodule), and many
datasets
attached to it.

Other Threads