Board index » delphi » blob memory consumption problem

blob memory consumption problem

Jeff, we are having a problem with reading a huge number of photos from a
database.  It seems the blob stream does not get freed untill you close the
query.  We found a ClearBlobCache function that clears it, but its
private -- so how can we clear TBlobArray, while iterating through a query?
Or would that be a bad thing?

Here is some sample code.  It loads data from "fromq" and inserts it into
two seperate tables (toq and q1):
var
    ms: TStream;
    toq, q1, fromq: TIBDataset;

(*all TIBDataset's have UniDirectional := True;*)

while not fromq.eof do
begin

    toq.Params[0] := fromq.Fields[0].AsInteger;
    toq.Params[1] := fromq.Fields[1].AsInteger;
    ...
    toq.Execute;

    ms := TVCSIBQuery(fromq).CreateBlobStream(fromq.fields[9], bmRead);
    q1.Params[0] := gid;
    q1.Params[1] := sid;
    q1.Params[2].LoadFromStream(ms);
    q1.Execute;

    ms.free;
    fromq.next;
end; //while

This code just keeps allocating ram, on a huge basis.  Is there a better way
to do this, or is clearing the blob cache my answer?

Thanks for your time.

-Andy (and imaginary friends)

 

Re:blob memory consumption problem


Quote
Andy wrote:

> Jeff, we are having a problem with reading a huge number of photos from a
> database.  It seems the blob stream does not get freed untill you close the
> query.  We found a ClearBlobCache function that clears it, but its
> private -- so how can we clear TBlobArray, while iterating through a query?
> Or would that be a bad thing?

Basically you can't.  The problem is that even in unidirectional mode you can go
back one record.  There is no mechanism in the BlobArray to tell what record it
belongs to so I can't tell when to clean up the ones no longer accessible.  I've
been meaning to look at this for D7 since the only way to fix it is some sort of
interface change to the caching mechanism (like storing the RecNo it is
associated with) so I can easily tell what items are no longer valid when in
unidirectional mode.

You can look at IBSQL instead, it uses a slightly different mechanism IIRC and
does not suffer from this.

(note - this is all from memory when I looked at this a couple of months ago and
I did not look at the code again while writing this).

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
This sad little lizard told me that he was a brontosaurus on his mother's
side.  I did not laugh; people who boast of ancestry often have little else
to sustain them.  Humoring them costs nothing and adds to happiness in
a world in which happiness is in short supply.   (RAH)

Other Threads