Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

PDF and GDI resources

edited November 2013 in General
Hello,

currently I experience a strange problem: When I dynamically create a report and export to a PDF device, some GDI resources seems not to be released again. Yes, I free all the instances afterwards.
So my applications runs out of resources and some other actions cannot be done - like loading images. Some more complex reports "lose" several hundred handles within a single run.

This is the procedure I use to export a producer:

type
TppStreamDeviceClass = class of TppStreamDevice;

procedure ktExportProducerToDeviceStream(AReport: TppProducer; AStream: TStream; ADeviceClass: TppStreamDeviceClass);
var
ADevice: TppStreamDevice;
begin
ADevice := ADeviceClass.Create(nil);
try
ADevice.OutputStream := AStream;
ADevice.Publisher := AReport.Publisher;
ADevice.PageSetting := psAll;
AReport.PrintToDevices;
ADevice.OutputStream := nil;
finally
FreeAndNil(ADevice);
end;
end;


Can anybody help? Thanks.

Best regards,
Michael

Comments

  • edited November 2013
    Hi Michael,

    Which version of ReportBuilder and Delphi are you using?

    How are you detecting a leak of resources? Are you using a memory
    manager such as FastMM? If not, I suggest running your application with
    one to see if it can give you some insight on where the leak is occurring.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2013
    Hello Nico,

    thank you for your reply! I use RB Builder Server 15.01 Build 2 and Delphi XE2 with Update 4.

    The application is a special service which performs several tasks. One of the tasks is generating PDFs from reports. I ran it on my local machine and watched the Windows 8 Taskmanager and the count of handles and GDI resources. With every single call to the PDF generation method the usage of the gdi resources have grown by aproximately 200 handles.

    I also extended one of the report builder examples (JIT Example) with the method posted previously and experienced a similar situation. But here the usage of resources grows just a single time because the report is created once - but does not return to the old value.

    How can FastMM be configured to detect "GDI" resource leaks?

    Best regards,
    Michael



    Am 06.11.2013 21:14, schrieb Nico Cizik (Digital Metaphors):
  • edited November 2013
    Hi Michael,

    You are correct, FastMM only detects memory leaks, not GDI resource issues.

    I did some tests with a sample report (using one of each component) and
    monitored the GDI resources used when exporting to PDF over and over.
    The resource count raised to a certain number then stopped regardless
    how many other PDF's I generated. This leads me to believe that the
    Windows/Delphi system is allocating these resources for the application
    to be reused if needed.

    This is not something we necessarily have control over. Most GDI work
    ReportBuilder does is though existing objects such as TBitmap or TFont,
    which would give a memory leak if they were not handled correctly.

    I also ran this report using AQTime and verified that no GDI resources
    are present after the application is closed (i.e. no leaks).

    If you have a specific report that demonstrates a different behavior,
    please send me an example I can run so this can be researched further.
    Send the exmaple in .zip format to support@digital-metaphor.com.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.