Recent

Author Topic: [SOLVED]Memory leak when using HTML tags, FpSpreadsheet 2.0  (Read 295 times)

Russ

  • Newbie
  • Posts: 2
[SOLVED]Memory leak when using HTML tags, FpSpreadsheet 2.0
« on: September 16, 2025, 02:18:55 pm »
I have an application which uses a TsWorkbookTabControl with a TsWorkseetGrid and a TsWorkbookSource. Extensive use is made HTML tags for text formatting. I have noticed that simply clicking on a cell that uses such formatting results in a memory leak.

This was traced to unit fpsHTMLUtils, function TsHTMLComposer.Exec(), line 1060 where prevFnt is created but never released. Enclosing the rest of the function in a Try-Finally where prevFnt is freed solves the problem. The patch is attached.

I tried to make a simple example app to illustrate the problem, but even though I used HTML tags, TsHTMLComposer.Exec() never gets called. I even tried testing with the fpsgrids example app, which uses rich text, and again TsHTMLComposer.Exec() never gets called, so I have no idea why there is different behavior with my code.
« Last Edit: September 23, 2025, 02:59:26 pm by Russ »

wp

  • Hero Member
  • *****
  • Posts: 13195
Re: Memory leak when using HTML tags, FpSpreadsheet 2.0
« Reply #1 on: September 16, 2025, 08:26:20 pm »
Thanks for reporting. Applied your patch.

Here is a small test project to demonstrate the issue before and its solution after applying the patch (requires "Use Heaptrc unit" in project options):
Code: Pascal  [Select][+][-]
  1. program project1;
  2. uses
  3.   SysUtils, fpSpreadsheet, fpsTypes, xlsxOOXML, fpsHTMLUtils;
  4. var
  5.   wbook: TsWorkbook;
  6.   wsheet: TsWorksheet;
  7.   cell: PCell;
  8.   s: String;
  9. begin
  10.   wbook := TsWorkbook.create;
  11.   try
  12.     wsheet := wbook.AddWorksheet('Page');
  13.     cell := wsheet.WriteTextAsHTML(0, 0, '<b>bold</b> <i>italic</i> normal');
  14.     RichTextToHTML(wbook, wsheet.ReadCellFont(cell),
  15.       cell^.UTF8StringValue, cell^.RichTextParams, s);
  16.     WriteLn(s);
  17. //    wbook.WriteToFile('rtf-cell.xlsx', true);
  18.   finally
  19.     wbook.Free;
  20.   end;
  21. end.

 

TinyPortal © 2005-2018