On 03/07/10 20:09, Oleg Mikheev wrote:
Hi guys and girls,

I'm doing a rather primitive thing: load and close a document.
Question: why does it make OO grow 50Mb/minute?

The Java-side proxy objects (referenced through variable xComponent) keep the OOo-side XComponent objects (representing the opened documents) alive until the JVM garbage collector decides to finalize them. Presumably, large parts of the OOo data structures for such a document are only released once the XComponent object is destroyed, and not already when XCloseable.close is called.

-Stephan

Code:

import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.CloseVetoException;
import com.sun.star.util.XCloseable;

public class Test2 {

        public static void main(String[] args) throws Exception {
                XComponentContext xCompContext =
com.sun.star.comp.helper.Bootstrap.bootstrap();
                XMultiComponentFactory xMCF = xCompContext.getServiceManager();
                Object xDesktop =
xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xCompContext);
                XComponentLoader aLoader =
UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);
                PropertyValue[] loadProps = new PropertyValue[]{new
PropertyValue("Hidden", 0, true, null)};
                while (true) {
                        XComponent xComponent =
aLoader.loadComponentFromURL("file:///tmp/demo.ods", "_blank", 0,
loadProps);
                        close(xComponent);
                }
        }

        private static void close(XComponent xComponent) {
                XCloseable xCloseable = 
UnoRuntime.queryInterface(XCloseable.class,
xComponent);
                if (xCloseable != null) {
                        try {
                                xCloseable.close(false);
                        } catch (CloseVetoException e) {}
                } else xComponent.dispose();
        }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to