#1 2014-08-06 08:58:43

proto
Member
From: Russia, Kostroma
Registered: 2011-09-12
Posts: 31

SOS! Not enough storage to process this command

I'm writing a simple directory to save the jewelry filtration. With the active use vyhodito error "Not enough memory to process this command", it generates a scroll pages back and forth.
I wrote a test case showing the problem. I'm on the 2950-2960 iteration pops overflow memory.
Please help solve the problem!

https://www.dropbox.com/s/zg0629isv7d7w … String.zip

  TSQLProduct = class(TSQLRecord)
  private
    fPreview: TSQLRawBlob;
  public
  published
    property preview: TSQLRawBlob read fPreview write fPreview;
  end;

var
  Form1: TForm1;
  Database: TSQLRestClientURI;
  Server: TSQLRestServerDB;
  model: TSQLModel;

implementation

{$R *.dfm}

function CreateModel: TSQLModel;
begin
  result := TSQLModel.Create([TSQLProduct]);
end;

procedure InitClient;
begin
  Model := CreateModel;
  Database := TSQLRestClientDB.Create(Model, CreateModel, 'test.db3', TSQLRestServerDB);
  if Database = nil then Exit;
  DataBase.ForceBlobTransfert := True;
  TSQLRestClientDB(Database).Server.CreateMissingTables(0);
end;

procedure FinalizeClient;
begin
  Server.Free;
  Database.Free;
  Model.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i, j, c: Integer;
  jpg: TJPEGImage;
  pic: RawByteString;
  prd: TSQLProduct;
begin
  c := 0;
  for j := 1 to 1000 do begin
    for i := 1 to 1000 do begin
        prd := TSQLProduct.Create(Database, i, False);
        try
          pic := prd.preview;
          inc(c);
          Caption := IntToStr(c);
          if pic <> '' then begin
            img.Picture := nil;
            img.Picture.Assign(LoadFromRawByteString(pic));
          end;
      finally
        FreeAndNil(prd);
      end;
      Application.ProcessMessages
    end;
  end;
end;

initialization
  Gdip := TGDIPlusFull.Create;
  InitClient;
finalization
  FinalizeClient();
end.

Last edited by proto (2014-08-06 09:04:36)

Offline

#2 2014-08-06 09:17:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: SOS! Not enough storage to process this command

I suppose your picture is internal loop is never released.

Perhaps you should better write:

  img.Picture.Free;
  img.Picture := nil;

Or use a local variable, with a try..finally block.

Offline

#3 2014-08-06 09:23:46

proto
Member
From: Russia, Kostroma
Registered: 2011-09-12
Posts: 31

Re: SOS! Not enough storage to process this command

is not the problem if you comment out these lines, the error is still there.

          if pic <> '' then begin
//            img.Picture := nil;
//            img.Picture.Assign(LoadFromRawByteString(pic));
            LoadFromRawByteString(pic)
          end;

error somewhere in the bowels function LoadFromRawByteString

Last edited by proto (2014-08-06 09:24:50)

Offline

#4 2014-08-06 09:30:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: SOS! Not enough storage to process this command

LoadFromRawByteString() returns a new TBitmap class instance which is never released by your loop!
The problem is not in LoadFromRawByteString() but in how you use it!

I suppose that if you write:

 LoadFromRawByteString(pic).Free;

there won't be any leak any more.

Offline

#5 2014-08-06 09:41:58

proto
Member
From: Russia, Kostroma
Registered: 2011-09-12
Posts: 31

Re: SOS! Not enough storage to process this command

thank you very much for your help, this is true, there are no memory leaks

Offline

Board footer

Powered by FluxBB