Page 1 of 1

[Delphi] LoadFromIStream

Posted: Fri Mar 13, 2015 4:38 pm
by BennyCUAG
Hello. We are using GDPicture with Delphi. It seems that using LoadFromIStream causes a memoryleak (fastmm ).
Here is a sample code:

Code: Select all

  ms := TMemoryStream.Create();
  ms.LoadFromFile('C:\temp\test.pdf');
  DociStream := TStreamAdapter.Create(ms,soOwned);

  GdPicturePDF1 := CreateComObject(CLASS_GdPicturePDF) as _GdPicturePDF;
  if GdPicturePDF1.LoadFromIStream(DocIStream) = 0 then begin
          GDPicturePDF1.CloseDocument;
  end;

  GdPicturePDF1 := nil;

  DociStream := nil; // nothing happened here
Memory Leaks:
TMemoryStream + TStreamAdapter

TMemoryStream should be released with TStreamAdapter but it seems TStreamAdapter isnt released. Any ideas why?

Edit - this works fine:

Code: Select all

  ms := TMemoryStream.Create();
  ms.LoadFromFile('C:\temp\test.pdf');
  DociStream := TStreamAdapter.Create(ms,soOwned);
  // no gdpicture here
  DociStream := nil; 

Re: [Delphi] LoadFromIStream

Posted: Sat May 16, 2015 4:04 pm
by Loïc
Hello,
TMemoryStream should be released with TStreamAdapter but it seems TStreamAdapter isnt released. Any ideas why?
To make it simple: GdPicture will never close the provided stream, this is not his task.

Just let me know if you need some elaboration.

Kind regards,

Loïc