Apache OpenOffice (AOO) Bugzilla – Issue 48642
Memory leak after making Writer tables via PyUNO session
Last modified: 2017-05-20 11:25:48 UTC
It seems that when you run OpenOffice.org as a "server" using the "accept" command line it is possible to make it leak memory by repeatedly running a Python script that connects with PyUNO, writes some tabular data into a Writer document, and then saves it as a PDF file. Our code is leaking around 1MB per script, but here is an example that seems to cause soffice.bin to leak around about 0.2MB per invocation: import uno from com.sun.star.beans import PropertyValue from com.sun.star.util import CloseVetoException from com.sun.star.lang import DisposedException from com.sun.star.io import IOException from com.sun.star.connection import NoConnectException from com.sun.star.util import XModifyListener import unohelper if __name__ == "__main__": local_context = uno.getComponentContext() local_service_manager = local_context.ServiceManager resolver = local_service_manager.createInstanceWithContext( 'com.sun.star.bridge.UnoUrlResolver', local_context) connection_string = \ "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" remote_context = resolver.resolve(connection_string) remote_service_manager = remote_context.ServiceManager desktop_class = 'com.sun.star.frame.Desktop' desktop = remote_service_manager.createInstanceWithContext(desktop_class, remote_context) properties = () url = "private:factory/swriter" document = desktop.loadComponentFromURL(url, "_blank", 0, properties) text = document.Text cursor = text.createTextCursor() text.insertString( cursor, "Hello World", 0 ) table_count = 0 while table_count < 5: table = document.createInstance( "com.sun.star.text.TextTable" ) table.initialize(40,4) text.insertTextContent( cursor, table, 0 ) for i in range(1, 41): for letter in ("A", "B", "C", "D"): name = "%s%i" % (letter, i) cell = table.getCellByName(name) cell_cursor = cell.createTextCursor() cell .setString(name) table_count += 1 export_format = "writer_pdf_Export" export_properties = (PropertyValue('FilterName', 0, export_format, 0), PropertyValue('Overwrite', 0, True, 0),) export_url = unohelper.systemPathToFileUrl("/home/gteale/foo.pdf") document.storeToURL(export_url, export_properties) try: document.close(True) except CloseVetoException: pass
Hi, how are you measuring the leak(s)? Can you reproduce it with a BASIC script running in process?
The real-world case where we see it is infact _always_ with BASIC code running inside Writer. We invoke a function that connects to a database and writes content out into tables on the page. We only invoke that function via PyUno. The exmple in PyUno (above) is just the simplest case I could produce to achieve a similar effect. To be clear, as far as I can tell it's the writing of tables that is causing the leak.
It IMHO already leaks when just opening&closing writer documents. At least on my Linux box the data segment is overall growing. Andreas, please take care of this.
Oliver, please check, if there's a memory leak and how we can avoid this.
Created attachment 26007 [details] java example
Executing the attached java code in a Windows non-pro on m100 costs about 1MB. It creates 5 documents, fills with tables and stores it to pdf. Without the tables it costs about 300 KB. Skipping PDF export doesn't change anything.
Reset assigne to the default "issues@openoffice.apache.org".