Bug 41288 - undefined: Memory leaks when open, get document text and close document by UNO
Summary: undefined: Memory leaks when open, get document text and close document by UNO
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: x86-64 (AMD64) Linux (All)
: high normal
Assignee: Not Assigned
URL:
Whiteboard: BSA
Keywords:
: 90524 (view as bug list)
Depends on:
Blocks: Memory
  Show dependency treegraph
 
Reported: 2011-09-28 03:38 UTC by Anatoly
Modified: 2023-12-02 13:34 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
An example document generating a larger memory leak than the document supplied with the official example. (539.04 KB, application/vnd.oasis.opendocument.text)
2023-11-26 17:53 UTC, WCDR
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anatoly 2011-09-28 03:38:04 UTC
Problem description:
Memory leaks in LibreOffice when I just open, get document text and close document several times using python-uno. But I think it is not problem of Python UNO but LibreOffice itself. All test was done on Ubuntu 11.04 + LibreOffice 3.4.3 + python-uno + python 2.7.1. I put the python code below just in case. Also I found that for GSOC 2011 one of ideas was "Search for, and fix memory and resource leaks" (http://wiki.documentfoundation.org/Development/Gsoc/Ideas#Search_for.2C_and_fix_memory_and_resource_leaks). It is why I think the problem is in libreoffice.

Steps to reproduce:
1. Start libreoffice in terminal without gui using following command: libreoffice --accept=socket,host=localhost,port=2002;urp;StarOffice.ServiceManager --norestore --nofirststartwizard --nologo --headless
2. In second terminal I starts python code to open some file, get text and close it several time
3. Using 'top' command I see that memory that libreoffice use is growing and growing.

Expected behavior:
Without memory leaks.

Minimum python code to reproduce problem (may be it helps):

import uno

local = uno.getComponentContext()
resolver = local.ServiceManager.createInstanceWithContext(
                  "com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve(
                'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
desktop = context.ServiceManager.createInstanceWithContext(
        "com.sun.star.frame.Desktop", context)

for i in range(1000):
    doc = desktop.loadComponentFromURL('some_url', "_blank", 0, ())
    plain_text = doc.Text.getString()
    doc.dispose()
    doc.close(False)
    del doc
Comment 1 Christopher Yeleighton 2012-03-24 12:25:03 UTC
I get this:

ImportError: No module named uno
Comment 2 Anatoly 2012-03-24 12:35:18 UTC
Please, install python-uno on Ubuntu:

sudo aptitude install python-uno


If you don't have LibreOffice you can also install it:

sudo aptitude install openoffice.org openoffice.org-writer
Comment 3 Christopher Yeleighton 2012-03-24 13:20:06 UTC
(In reply to comment #0)
>     doc = desktop.loadComponentFromURL('some_url', "_blank", 0, ())

__main__.IllegalArgumentException: URL seems to be an unsupported one.
Comment 4 Anatoly 2012-03-25 11:16:14 UTC
Instead of "some_url" you can use any url to file with document. For example, I have:
http://dl.dropbox.com/u/318944/python-uno/hello.doc
Comment 5 Julien Nabet 2012-05-18 04:53:48 UTC
I know very little about uno. On pc Debian x86-64, with master branch updated today, I tried to reproduce the pb and had this :
warn:legacy.osl:23080:1:/home/julien/compile-libreoffice/libo/desktop/source/app/appinit.cxx:276: Acceptor could not be created.
bash: urp : commande introuvable
bash: StarOffice.ServiceManager : commande introuvable

("commande introuvable" is French and means "unfound/unknown command")

Could you give a try to a newer version of LO 3.5.3 ?
Comment 6 Anatoly 2012-05-18 05:32:52 UTC
(In reply to comment #5)
> I know very little about uno. On pc Debian x86-64, with master branch updated
> today, I tried to reproduce the pb and had this :
> warn:legacy.osl:23080:1:/home/julien/compile-libreoffice/libo/desktop/source/app/appinit.cxx:276:
> Acceptor could not be created.
> bash: urp : commande introuvable
> bash: StarOffice.ServiceManager : commande introuvable
> 
> ("commande introuvable" is French and means "unfound/unknown command")
> 
> Could you give a try to a newer version of LO 3.5.3 ?

 Really, doesn't matter UNO or you can just open and close any a doc-file several hundreds times. Memory leaks inside LibreOffice itself.

  But anyway you can close this bug because we can't use LibreOffice for our project by several reasons. Most of all LibreOffice doesn't understand MS Word format correctly. Often styles of documents are broken after document was open and save. Sorry, It's another story.
Comment 7 Julien Nabet 2012-05-18 05:44:18 UTC
First thank you for your quick feedback.

About Word document, LO has improved a lot since 3.4.3, you should try last version 3.5.3.2.
In addition with new functions, there have been lots of fixes, perf optimization and memory leaks fixes, cleaning, etc.

Don't hesitate to open a new tracker with a Word file (or several) which don't work.
Comment 8 QA Administrators 2013-05-26 22:31:23 UTC Comment hidden (obsolete)
Comment 9 QA Administrators 2013-07-08 21:21:47 UTC Comment hidden (obsolete)
Comment 10 Buovjaga 2015-04-16 11:03:09 UTC
Setting to NEW as this was confirmed in a new report, bug 90524.
Comment 11 Buovjaga 2015-04-16 11:03:42 UTC
*** Bug 90524 has been marked as a duplicate of this bug. ***
Comment 12 Samuel Monsarrat 2015-11-19 09:23:31 UTC
This is a very old bug that has been around for years and years and was reported many times in OpenOffice long before the advent of LO.
I reported https://bz.apache.org/ooo/show_bug.cgi?id=105191 back in 2009 but the bug goes back farther then that.
Comment 13 QA Administrators 2017-01-03 19:34:45 UTC Comment hidden (obsolete)
Comment 14 QA Administrators 2021-01-11 03:56:12 UTC Comment hidden (obsolete)
Comment 15 QA Administrators 2023-01-12 03:21:02 UTC Comment hidden (obsolete)
Comment 16 WCDR 2023-11-26 17:53:32 UTC
Created attachment 191046 [details]
An example document generating a larger memory leak than the document supplied with the official example.
Comment 17 WCDR 2023-11-26 18:13:22 UTC
Tested in November 2023: Ubuntu 20 with LO v6.4.7.2 and 7.5.8.2.
> Still there via a C++ call.

An easy way to generate the problem is to use the example provided with the SDK: https://api.libreoffice.org/examples/cpp/DocumentLoader/

1 - on T1 : libreoffice "--accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"
2 - Run ubuntu "system monitor" with a "soffice" filter
3 - Note the memory value ~ 50Mb
4 - On T2 run the sample with the sample provided or the document I have attached.
5 - Note the memory value
6 - Repeat steps 4-5-...
After 1000 tasks, the process memory usage is ~ 1.2 Gb

Add: xComponent->dispose (); after loadComponentFromURL helps a little, but not that much.

If you put a loop around loadComponentFromURL, you have the same problem, the problem seems to be located in the code behind loadComponentFromURL.

Removing the loadComponentFromURL line removes the leak...

Even when waiting, memory consumption doesn't decrease...

This bug is a real problem, because having to close the process and reopen it takes an enormous amount of time that is not compatible with microservice architecture, and the size of the leak is a problem for the sizing and the execution environment.

If I can help by doing some tests, I'm finishing compiling libreoffice-core today... however, I don't do Python...

Regards
Comment 18 WCDR 2023-11-26 19:55:54 UTC
Example of a community tool affected by these bugs:
https://github.com/unoconv/unoserver/issues/74
https://github.com/unoconv/unoserver/issues/83
Comment 19 WCDR 2023-11-27 06:31:26 UTC
The same problem occurs when you use the user interface to open several documents: writer, drawer... until you close the last instance, the memory keeps increasing...
Comment 20 Hossein 2023-11-27 15:26:15 UTC
This problem seems to be Linux specific, as I could not reproduce the problem with LibreOffice 7.6 on Windows:

Version: 7.6.2.1 (X86_64) / LibreOffice Community
Build ID: 56f7684011345957bbf33a7ee678afaf4d2ba333
CPU threads: 20; OS: Windows 10.0 Build 22621; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded

The memory usage is stable around 330 MB, and does not change much after 1000 tasks created with the provided Python code and the sample attached document.
Comment 21 Hossein 2023-11-27 18:26:52 UTC
On Linux, I get an exception when using debug build:

warn:sal.osl:76556:76562:sal/osl/unx/socket.cxx:1573: receive socket [0] failed: EOL
Traceback (most recent call last):
  File "memory.py", line 12, in <module>
    doc = desktop.loadComponentFromURL('file:///.../document.odt', "_blank", 0, ())
__main__.DisposedException: Binary URP bridge disposed during call at /home/user/core/binaryurp/source/bridge.cxx:615

Version: 24.2.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: 45217ca5ba0d4e78b462a10072a4334342cc402c
CPU threads: 12; OS: Linux 6.2; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: CL threaded

On the other hand, I could reproduce the problem on Linux release. After 1000 tasks, the memory consumption went above 1.5 GB.

Version: 7.6.1.2 (X86_64) / LibreOffice Community
Build ID: f5defcebd022c5bc36bbb79be232cb6926d8f674
CPU threads: 12; OS: Linux 6.2; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 22 WCDR 2023-12-02 13:34:32 UTC
Same issue using bootstrap (automatic pipe)

Reference<XComponentContext> const xContext { bootstrap ()};
Reference<XMultiComponentFactory> const xFactory { xContext->getServiceManager ()};
...