Recent

Author Topic: Memory Leak when Reading ODS  (Read 1824 times)

sfeinst

  • Full Member
  • ***
  • Posts: 230
Memory Leak when Reading ODS
« on: July 13, 2023, 05:08:52 pm »
I am trying out fpspreadsheet.  I downloaded v1.14.  When I execute following code, I am getting unfreed memory from heaptrc (I compiled with -gh option).  I've tried Free instead of Destroy (didn't think it would matter, but examples used free) and still get the memory leak.  The data displays from the writeln correctly.  But then get the stack trace/memory leak info.  I attached the file I am using as a test.  Guessing I'm doing something wrong, just not sure since this is a simple test.

Code: Pascal  [Select][+][-]
  1. program testfpspread;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   fpspreadsheet, fpstypes, fpsopendocument;
  7.  
  8. var
  9.   wb: TsWorkbook;
  10.   ws: TsWorksheet;
  11.   S: string;
  12. begin
  13.   wb := TsWorkbook.Create;
  14.   try
  15.     wb.ReadFromFile('/home/steve/temp/test.ods', sfOpenDocument);
  16.     ws := wb.GetWorkSheetByName('Teams');
  17.     S := ws.ReadAsText(0,0);
  18.     writeln('Data: ', S);
  19.   finally
  20.     wb.Destroy;
  21.   end;
  22. end.
  23.  
  24.  

sfeinst

  • Full Member
  • ***
  • Posts: 230
Re: Memory Leak when Reading ODS
« Reply #1 on: July 13, 2023, 05:20:11 pm »
Just as a test, I saved the ODS from within LibreOffice to an xlsx file.
I changed the uses to use xlsxooxml
I changed the open to use     wb.ReadFromFile('/home/steve/temp/test.xlsx', sfOOXML);

and no memory leak.

It appears to be limited to just using the ODS version of the file.

wp

  • Hero Member
  • *****
  • Posts: 11995
Re: Memory Leak when Reading ODS
« Reply #2 on: July 14, 2023, 01:40:48 am »
This has been fixed in the svn version last year. Guess it's time to prepare another release version for OPM...

sfeinst

  • Full Member
  • ***
  • Posts: 230
Re: Memory Leak when Reading ODS
« Reply #3 on: July 14, 2023, 06:58:46 am »
This has been fixed in the svn version last year. Guess it's time to prepare another release version for OPM...

Is the memory leak just on the destroy of the workbook?  If I code using current version and I only create and destroy the workbook once in my application (the rest of the time will be processing worksheets), will I not really have a leak?  I assume the OS will return the memory to the available to use pool, so though not optimal, I'm not really going to leak memory because the destroy does not occur until the end.  Or are there other potential memory issues as I traverse the worksheets?

Obviously, I want to use fixed code, but until it is ready, I can continue with current code.

wp

  • Hero Member
  • *****
  • Posts: 11995
Re: Memory Leak when Reading ODS
« Reply #4 on: July 14, 2023, 10:00:29 am »
The memory leak is created during reading of the ods file: ods contains several xml files which are read by means of the ReadXMLStream method into a  TXMLDocument instance - and this document is not destroyed in your version. Since the operating systems releases all memory needed by an application at its end this memory leak has no effect on your system as long as you read only a few files. However, when you process a great number of ods files within the same session of your application there is a chance that you may run out of memory. The main issue with a memory leak is that it makes it more difficult to find other memory leaks in an application due to the myriad of messages created by heaptrc.

sfeinst

  • Full Member
  • ***
  • Posts: 230
Re: Memory Leak when Reading ODS
« Reply #5 on: July 14, 2023, 03:33:00 pm »
Thank you for the response.  I can at least continue coding to get the app working and will know to limit it to one workbook an execution until there is a new release ready.

 

TinyPortal © 2005-2018