Page 1 of 1

Teecreatebitmap

Posted: Wed Aug 05, 2009 9:35 pm
by 10546846
I'm using code below to make gf files of chart, the loop can be executed many hundreds of times. There appears to be a memory leak with this, should I be freeing something after the call to teecreatebitmap?

thans
Sean

tmpgif:=tgifimage.Create;
for c:=1 to no_of_var do
begin
get_chart1;
with tmpgif do
begin
compression:=gcLZW;
dithermode:=dmstucki;
colorreduction:=rmquantizewindows;
begin
assign(chart1.TeeCreateBitmap(chart1.Color,rect(0,0,chart1.Width,chart1.Height)));
savetofile(fname1);
end
end;
end;
tmpgif.Free;

Re: Teecreatebitmap

Posted: Fri Aug 07, 2009 9:44 am
by yeray
Hi Sean Murphy,

I think that using an intermediate temporal Bitmap to store the TeeCreateBitmap result and freeing it at each iteration would solve the problem. Something like this:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var series1: TChartSeries;
    tmpgif: TGIFImage;
    tmpBitmap: TBitmap;
    c, no_of_var: Integer;
    fname1: string;
begin
  no_of_var := 100;
  for c:=1 to no_of_var do
  begin
    tmpgif:=tgifimage.Create;
    with tmpgif do
    begin
      Compression:=gcLZW;
      DitherMode:=dmStucki;
      ColorReduction:=rmQuantizeWindows;
      fname1 := 'C:\tmp\pics\tmpGif' + IntToStr(c) + '.gif';
      tmpBitmap := chart1.TeeCreateBitmap(Chart1.Color,Rect(0,0,Chart1.Width,Chart1.Height));
      Assign(tmpBitmap);
      SaveToFile(fname1);
    end;
    FreeAndNil(tmpgif);
    FreeAndNil(tmpBitmap);
  end;

  ShowMessage('Process Finished!');
end;