Bug 159680 - Memory not freed after PDF export
Summary: Memory not freed after PDF export
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.5.0.3 release
Hardware: All macOS (All)
: medium normal
Assignee: Patrick (volunteer)
URL:
Whiteboard: target:25.2.0 target:24.2.5 target:24...
Keywords: bibisected, bisected, regression
Depends on:
Blocks: PDF-Export Memory
  Show dependency treegraph
 
Reported: 2024-02-11 10:43 UTC by Telesto
Modified: 2024-07-04 10:32 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Snapsot of Instruments app with the stack of the largest leak (1.90 MB, image/png)
2024-06-27 23:17 UTC, Patrick (volunteer)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Telesto 2024-02-11 10:43:39 UTC
Description:
Memory not freed after PDF export

Steps to Reproduce:
1. Open attachment 192460 [details] (takes a while to open, 1500 pages)
2. Open a process monitor to check memory usage
3. Save as PDF 


Actual Results:
* Memory usage increases to from 1,5 to 4 GB (feels excessive) while exporting with ba8f4bff6015013013df652efbfaf4d9ae10c881
* The RAM usage is sticky. Close the document after export. 


Expected Results:
Primary, free ram after export


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: ba8f4bff6015013013df652efbfaf4d9ae10c881
CPU threads: 8; OS: macOS 14.3; UI render: Skia/Raster; VCL: osx
Locale: nl-NL (nl_NL.UTF-8); UI: en-US
Calc: threaded
Comment 1 m_a_riosv 2024-02-11 15:44:58 UTC
On Windows with Skia/Vulkan:
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 17fc445938dedb05125a6d6a5b4ce7f34ea95f59
CPU threads: 16; OS: Windows 10.0 Build 22631; UI render: Skia/Vulkan; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL threaded

After open the file: 0.6 GB
After export to PDF: 0.7 GB

On Windows with Skia/Raster:
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 17fc445938dedb05125a6d6a5b4ce7f34ea95f59
CPU threads: 16; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL threaded

After open the file: 0.5 GB
After export to PDF: 0.5 GB

On Windows with default:
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 17fc445938dedb05125a6d6a5b4ce7f34ea95f59
CPU threads: 16; OS: Windows 10.0 Build 22631; UI render: default; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL threaded

After open the file: 0.5 GB
After export to PDF: 0.5 GB
Comment 2 Telesto 2024-02-11 16:37:32 UTC
Similar to comment 1 with Windows
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 4d381b54d1c598c181b4a21a8bf0db86eb4668d1
CPU threads: 4; OS: Windows 6.3 Build 9600; UI render: Skia/Raster; VCL: win
Locale: nl-NL (nl_NL); UI: en-US
Calc: CL threaded

The document is only using 295 MB in my case on export 421 MB. Drops nicely after closing the window. Different story for macOS
Comment 3 Stéphane Guillou (stragu) 2024-02-27 08:11:33 UTC
Tested on Linux:

Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: d2fa44db6f8a1badece63856ee0f12db4cba9b28
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded

When opened, settles at about 830 mb.
When exporting, goes to 900 mb.
Settles back to 880 mb afterwards.
If I export again, it settles to 910 mb, but doesn't go further with subsequent exports.

It does look macOS-specific.
Comment 4 Dennis Roczek 2024-02-29 15:34:46 UTC
Confirmed using

Version: 24.2.0.3 (X86_64) / LibreOffice Community
Build ID: da48488a73ddd66ea24cf16bbc4f7b9c08e9bea1
CPU threads: 4; OS: macOS 11.7.10; UI render: Skia/Raster; VCL: osx
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Calc: threaded

from ~690mb
up to 3,53GB
"going back" after export 3,54GB
Comment 5 Dennis Roczek 2024-02-29 15:36:58 UTC
(In reply to Dennis Roczek from comment #4)
> Confirmed using
> 
> Version: 24.2.0.3 (X86_64) / LibreOffice Community
> Build ID: da48488a73ddd66ea24cf16bbc4f7b9c08e9bea1
> CPU threads: 4; OS: macOS 11.7.10; UI render: Skia/Raster; VCL: osx
> Locale: de-DE (de_DE.UTF-8); UI: de-DE
> Calc: threaded
> 
> from ~690mb
> up to 3,53GB
> "going back" after export 3,54GB

missed: but even when closing the document, it still stays at 3,31GB in my case! o.O
Comment 6 Telesto 2024-06-26 20:51:03 UTC
Still present
Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: aaf2967d74a9a7ba2d28433e1872422ce38b6244
CPU threads: 8; OS: macOS 14.3; UI render: Skia/Raster; VCL: osx
Locale: nl-NL (nl_NL.UTF-8); UI: en-US
Calc: threaded
Comment 7 Telesto 2024-06-27 13:18:13 UTC
@Patrick
Would be nice if you could peak into this some day, if you're interest of course. This might be very specific corner case, or making a general existing issue very visible.. No clue

There are more issues with PDF export with sticky ram usage, this one is somehow macOS specific
Comment 8 Patrick (volunteer) 2024-06-27 23:17:11 UTC
Created attachment 195028 [details]
Snapsot of Instruments app with the stack of the largest leak
Comment 9 Patrick (volunteer) 2024-06-27 23:24:41 UTC
(In reply to Patrick Luby (volunteer) from comment #8)
> Created attachment 195028 [details]
> Snapsot of Instruments app with the stack of the largest leak

I connected the Instruments application to LibreOffice running from my local master build (you can also connect Instruments to nightly builds as well), opened https://bugs.documentfoundation.org/attachment.cgi?id=192460, exported to PDF from the toolbar button, and closed the document window.

In attachment #195028 [details], the Allocations graph is at 3.0 GB and the lowest function call in the largest leak's stack (i.e. the selected line near the bottom right corner) is 2.85 GB. Seems like a pretty specific macOS-only memory leak so I'll look at the code tomorrow and post again when I have some news.
Comment 10 Dennis Roczek 2024-06-28 10:00:23 UTC
Just realizing: this is not happening with


Version: 7.2.0.0.alpha1+ / LibreOffice Community
Build ID: ff2ba77f22b2e96f96f5537aec1705956b47583d
CPU threads: 4; OS: Mac OS X 10.16; UI render: default; VCL: osx
Locale: de-DE (de_DE.UTF-8); UI: en-US
Calc: threaded

will do a bibisect.
Comment 11 Commit Notification 2024-06-28 11:23:43 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/2e87c644245751aea9f50faf16c4ca4d57b0c2f1

tdf#159680 fix memory leak of CTFontRef

It will be available in 25.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 Patrick (volunteer) 2024-06-28 11:33:51 UTC
(In reply to Dennis Roczek from comment #10)
> Just realizing: this is not happening with
> 
> 
> Version: 7.2.0.0.alpha1+ / LibreOffice Community
> Build ID: ff2ba77f22b2e96f96f5537aec1705956b47583d
> CPU threads: 4; OS: Mac OS X 10.16; UI render: default; VCL: osx
> Locale: de-DE (de_DE.UTF-8); UI: en-US
> Calc: threaded
> 
> will do a bibisect.

No need. This was a memory leak in macOS native code that I have already fixed.
Comment 13 Patrick (volunteer) 2024-06-28 11:34:35 UTC
I have committed a fix this bug. The fix should be in tomorrow's (29 June 2024) nightly master builds:

https://dev-builds.libreoffice.org/daily/master/current.html

Note for macOS testers: the nightly master builds install in /Applications/LibreOfficeDev.app. These builds are not codesigned like regular LibreOffice releases so you will need to execute the following Terminal command after installation but before you launch /Applications/LibreOfficeDev:

xattr -d com.apple.quarantine /Applications/LibreOfficeDev.app
Comment 14 Dennis Roczek 2024-06-28 12:52:19 UTC
(In reply to Patrick Luby (volunteer) from comment #12)
> (In reply to Dennis Roczek from comment #10)
> > Just realizing: this is not happening with
> > 
> > 
> > Version: 7.2.0.0.alpha1+ / LibreOffice Community
> > Build ID: ff2ba77f22b2e96f96f5537aec1705956b47583d
> > CPU threads: 4; OS: Mac OS X 10.16; UI render: default; VCL: osx
> > Locale: de-DE (de_DE.UTF-8); UI: en-US
> > Calc: threaded
> > 
> > will do a bibisect.
> 
> No need. This was a memory leak in macOS native code that I have already
> fixed.

Just for the reference: the first bad commit was
https://git.libreoffice.org/core/+/164d717530aff8d2581d0a2ff249f83aabb27502

I did read that too late ;-)
Comment 15 Commit Notification 2024-06-29 20:36:53 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "libreoffice-24-2":

https://git.libreoffice.org/core/commit/b0f047a710dd9bb69a12eeae24a116c74b42ce81

tdf#159680 fix memory leak of CTFontRef

It will be available in 24.2.5.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 16 Commit Notification 2024-07-04 10:32:11 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/f18e9d5c1bf23306efb2941170decf2f002322d5

tdf#159680 fix memory leak of CTFontRef

It will be available in 24.8.0.0.beta2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.