Kaynağa Gözat

* fcl-db: limit blob memory usage when using unidirectional datasets. Patch by Laco. Issue #24509

git-svn-id: trunk@27830 -
reiniero 11 yıl önce
ebeveyn
işleme
e8a3715afd
1 değiştirilmiş dosya ile 15 ekleme ve 6 silme
  1. 15 6
      packages/fcl-db/src/base/bufdataset.pas

+ 15 - 6
packages/fcl-db/src/base/bufdataset.pas

@@ -2066,7 +2066,7 @@ end;
 function TCustomBufDataset.LoadBuffer(Buffer : TRecordBuffer): TGetResult;
 
 var NullMask        : pbyte;
-    x               : longint;
+    i               : longint;
     CreateBlobField : boolean;
     BufBlob         : PBufBlobField;
 
@@ -2081,21 +2081,30 @@ begin
     Exit;
     end;
 
+  if IsUniDirectional then
+    begin
+    // release blob buffers before new record is loaded
+    // in order to save memory
+    for i := 0 to high(FBlobBuffers) do
+      FreeBlobBuffer(FBlobBuffers[i]);
+    SetLength(FBlobBuffers, 0);
+    end;
+
   NullMask := pointer(buffer);
   fillchar(Nullmask^,FNullmaskSize,0);
   inc(buffer,FNullmaskSize);
 
-  for x := 0 to FieldDefs.Count-1 do
+  for i := 0 to FieldDefs.Count-1 do
     begin
-    if not LoadField(FieldDefs[x],buffer,CreateBlobField) then
-      SetFieldIsNull(NullMask,x)
+    if not LoadField(FieldDefs[i], buffer, CreateBlobField) then
+      SetFieldIsNull(NullMask,i)
     else if CreateBlobField then
       begin
       BufBlob := PBufBlobField(Buffer);
       BufBlob^.BlobBuffer := GetNewBlobBuffer;
-      LoadBlobIntoBuffer(FieldDefs[x],BufBlob);
+      LoadBlobIntoBuffer(FieldDefs[i], BufBlob);
       end;
-    inc(buffer,GetFieldSize(FieldDefs[x]));
+    inc(buffer, GetFieldSize(FieldDefs[i]));
     end;
   Result := grOK;
 end;