Page 1 of 1

Memory leak in TeeSaveToBitmap()

Posted: Tue Jun 19, 2012 10:48 am
by 10049140
Hi.

I am using latest version of TeeChart Pro VCL (v2012.05.120327).

I encountered a memory leak when calling TeeSaveToBitmap() in unit TeeBMPOptions to save my pie chart to a bitmap file.
It seems like an object of the type TBMPOptions is not correctly freed.

Is this a known issue?
Is there a fix for this issue?

Please contact me in case you need any additional information.
Best regards!

Re: Memory leak in TeeSaveToBitmap()

Posted: Wed Jun 20, 2012 3:58 pm
by 10050769
Hello marder,

I inform you that the last version of TeeChart Pro VCL isn't v2012.05.120327, so there do few days we published a newest version 2012.06.120613. Please, can you update your version and check if your problem persist. If your problem persist please let me know.

Thanks,

Re: Memory leak in TeeSaveToBitmap()

Posted: Mon Aug 27, 2012 9:03 am
by 10049140
Hello Sendra,

I updated to latest version (v2012.06.120613) and the issue still persists.

The call of TeeBMPOptions.TeeSaveToBitmap() leads to a memory leak (detected by FastMM).
Image

Best regards!

Re: Memory leak in TeeSaveToBitmap()

Posted: Mon Aug 27, 2012 1:42 pm
by yeray
Hi,

We've reproduced it and already fixed it for the next maintenance release.
Since you are a source code customer, here you have the changes:

At TeeBmpOptions.pas, these functions:

Code: Select all

Function TBMPExportFormat.Bitmap(const AOptions:TBMPOptions):TBitmap;
begin
  CheckProperties;
  if Assigned(AOptions) then FProperties:=AOptions;
  result:=InternalGetBitmap;
  FFilters.ApplyTo(result);
end;

Code: Select all

Procedure TeeSaveToBitmap( APanel:TCustomTeePanel;
                           Const FileName: WideString;
                           Const R:TRect;
                           Dpi: Integer = 0);
var tmp         : String;
    tmpWidth,
    tmpHeight   : Integer;
    FProperties : TBMPOptions;
begin
    { verify filename extension }
  tmp:=FileName;

  if ExtractFileExt(tmp)='' then
     tmp:=tmp+'.bmp'; // Do not localize

  FProperties:=TBMPOptions.Create(nil);
  FProperties.UDDpi.Position:=Dpi;

  tmpWidth:=R.Right-R.Left;
  tmpHeight:=R.Bottom-R.Top;

  if tmpWidth<=0 then tmpWidth:=APanel.Width;
  if tmpHeight<=0 then tmpHeight:=APanel.Height;

  TBMPExportFormat.SaveToFile(APanel, tmp, FProperties, tmpWidth, tmpHeight);
end;
Are now:

Code: Select all

Function TBMPExportFormat.Bitmap(const AOptions:TBMPOptions):TBitmap;
begin
  if Assigned(AOptions) then FProperties:=AOptions
                        else CheckProperties;

  result:=InternalGetBitmap;
  FFilters.ApplyTo(result);

  if Assigned(AOptions) then
     FProperties:=nil;  
end;

Code: Select all

Procedure TeeSaveToBitmap( APanel:TCustomTeePanel;
                           Const FileName: WideString;
                           Const R:TRect;
                           Dpi: Integer = 0);
var tmp         : String;
    tmpWidth,
    tmpHeight   : Integer;
    FProperties : TBMPOptions;
begin
    { verify filename extension }
  tmp:=FileName;

  if ExtractFileExt(tmp)='' then
     tmp:=tmp+'.bmp'; // Do not localize

  FProperties:=TBMPOptions.Create(nil);
  try
    FProperties.UDDpi.Position:=Dpi;

    tmpWidth:=R.Right-R.Left;
    tmpHeight:=R.Bottom-R.Top;

    if tmpWidth<=0 then tmpWidth:=APanel.Width;
    if tmpHeight<=0 then tmpHeight:=APanel.Height;

    TBMPExportFormat.SaveToFile(APanel, tmp, FProperties, tmpWidth, tmpHeight);
  finally
    FProperties.Free;
  end;
end;
And at TeeExport.pas, at the procedure TTeeExportFormat.SaveToFile, where says:

Code: Select all

TTeeExportFormat.SaveToFile(const FileName: String;
//...
    {$IFNDEF TEEOCX} // Revise for 5.04
    Options;
    {$ENDIF}
//...
Now is:

Code: Select all

TTeeExportFormat.SaveToFile(const FileName: String;
//...
    {$IFNDEF TEEOCX} // Revise for 5.04
    if not Assigned(AOptions) then
      Options;
    {$ENDIF}
//...

Re: Memory leak in TeeSaveToBitmap()

Posted: Mon Aug 27, 2012 1:56 pm
by 10049140
Hi Yeray,

Thank you for the fast feedback and the fix!

Best Regards!