WPTools + Report Builder wrapper => image memory handlin

  • Hi,

    I was searching for some problems with memory allocation while printing report with Report Builder and find out that there is a problem withing Report Builder wrapper for WPTools.

    The main problem is, that Report Builder wrapper is using following code in SetRichText method:

    Code
    FPaintEngine.RTFData.SetANSIString(Value);
      FixTables;
      FPaintEngine.ReformatAll(True);
      FreeAndNil(FCurrentPageImage);

    but there is a problem, that FPaintEngine.RTFData.SetAnsiString call creates all necessary TWPObject's, but doesn't Destroy already created ones. So if you use TppWPRichText component on detail band and you print rich text with many images within RTF, you end up with Out of memory exception. The wrapper creates just one instance of TppWPRichText and reloads its content for each detail band. It ends up that there can be more then 1000 TWPobject instances in memory and all these created TWPObject's descendands are destroyed after destroying FPaintEngine object. No memry leaks are detected - this is just problem with memory allocation while generating report. After destroying report all memory is freed correctly.

    I modified the source that I destroy and create FPaintEngine before calling SetAnsiString method and all memory problems are gone. Is there any other method how to destroy unecessary TWPObjects in FPaintEngine? Can you also update the source to correct this bug?

    After fixing this issue, I was able to print report with more than 1000 pages without any issue. I was able to print only about 200 pages and the app crashed before applying fix.

    Petr Slipek.