To comment on the following update, log in, then open the issue:
http://www.openoffice.org/issues/show_bug.cgi?id=91554
                 Issue #|91554
                 Summary|Mail merge memory leak
               Component|Word processor
                 Version|OOo 2.4.1
                Platform|Unknown
                     URL|
              OS/Version|Linux
                  Status|UNCONFIRMED
       Status whiteboard|
                Keywords|
              Resolution|
              Issue type|DEFECT
                Priority|P3
            Subcomponent|programming
             Assigned to|mru
             Reported by|starm





------- Additional comments from [EMAIL PROTECTED] Thu Jul 10 16:33:06 +0000 
2008 -------
In Linux and Windows, the mail merge had a memory leak.
I call it in java with uno api.

It is easy to reproduce the bug with a little java program. If the mail merge is
in a loop (only the merge, not the connexion and other component) 

for (int i=0; i<100; i++)
{
   job.execute(new NamedValue[0]);
}

the size of memory grow up.
If you use this command in linux "ls -al /proc/5774/fd/ | wc -l", you can see
OOo create temporary files and the number of temporary grow up.


I take a part of my code in OOo snippet :
http://codesnippets.services.openoffice.org/Writer/Writer.MailMerge.snip

With this problem, in windows, the processus soffice can grow up until 1Go.

My code to reproduce the problem :

package openoffice;


import com.sun.star.beans.NamedValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.bridge.XBridge;
import com.sun.star.bridge.XBridgeFactory;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.connection.XConnection;
import com.sun.star.connection.XConnector;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.task.XJob;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public class MailMerger {

    // These objects are used for creating and accessing OpenOffice.org API 
objects

    private XMultiComponentFactory mxMCF;
    private XMultiServiceFactory mxMSF;
    private XComponentContext mxComponentContext;
    private XComponentLoader mxComponentLoader;
    XBridge bridge;

    // The default connection string used to connect to running OpenOffice.org
    public static final String DEFAULT_CONNECTION_STRING =
        "socket,host=sldbe3a,port=8099";

    // The URL of the directory with the Data Source tables
    private String mDataSourceDir;

    // The name of the Data Source to be used for the mail merge
    private String mDataSourceName;

    // The name of the Table in that Data Source to used for the mail merge
    private String mTableName;

    // The URL to which the generated template should be saved
    private String mFileURL;

    public MailMerger(String dsdir, String file, String db, String table) {
        mDataSourceDir = dsdir;
        mFileURL = file;
        mDataSourceName = db;
        mTableName = table;
    }

    public MailMerger(String file, String db, String table) {
        mFileURL = file;
        mDataSourceName = db;
        mTableName = table;
    }

    public static void main(String args[]) {

        if (args.length < 4) {
            printUsage();
            System.exit(1);
        }

        if (args[0].equals("-merge") && args.length == 4) {
            MailMerger mm = new MailMerger(args[1], args[2], args[3]);
                mm.setupConnection();
                mm.doMerge();
                mm.fermerConnec();
        }
        else {
            printUsage();
            System.exit(1);
        }
    }

    public static void printUsage() {
        System.err.println(
            "Usage: java MailMerger -create <URL of Data Source directory> " +
            "<URL to save template file> " +
            "<Data Source name> <Table name>");

        System.err.println(
            "Usage: java MailMerger -merge " + "<URL of template file> " +
            "<Data Source name> <Table name>");

        System.err.println("\ne.g.:");

        System.err.println("java MailMerger -create file://" +
            System.getProperty("user.home") +
            "/mydatasourcedir file://" +
            System.getProperty("user.home") +
            "/mytemplate.stw mydatasource mytable");

        System.err.println("java MailMerger -merge file://" +
            System.getProperty("user.home") +
            "/mytemplate.stw mydatasource mytable");
    }
    
    public void fermerConnec()
    {
        System.out.println("fermeture");
        XComponent xcomponent = (XComponent)
UnoRuntime.queryInterface(XComponent.class, bridge);
        if (xcomponent != null)
        {
            
            // Closing the bridge
            System.out.println("avant fermeture");
            xcomponent.dispose();
            System.out.println("après fermeture");
        }
    }

    // Refer to DevelopersGuide.pdf, p30-33, "2.3.4 First Connection".
    public void setupConnection() {
        try {
            /* Bootstraps a component context with the jurt base components
               registered. Component context to be granted to a component for
               running. Arbitrary values can be retrieved from the context. */
            mxComponentContext =
                Bootstrap.createInitialComponentContext(null);

            Object x =
mxComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.connection.Connector",
mxComponentContext);
            
            XConnector xConnector = (XConnector)
UnoRuntime.queryInterface(XConnector.class, x);
            
            XConnection connection = null;
            
            connection = xConnector.connect(DEFAULT_CONNECTION_STRING);
            
            x =
mxComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.bridge.BridgeFactory",
mxComponentContext);

            XBridgeFactory xBridgeFactory = (XBridgeFactory)
UnoRuntime.queryInterface(XBridgeFactory.class, x);

            bridge = xBridgeFactory.createBridge("TEST", "urp", connection, 
null);
            
            x = bridge.getInstance("StarOffice.ServiceManager");
            // Query the initial object for its main factory interface
            mxMCF = (XMultiComponentFactory)
UnoRuntime.queryInterface(XMultiComponentFactory.class, x);

            // Query for the XPropertySet interface.
            XPropertySet xpropertysetMultiComponentFactory = (XPropertySet)
                UnoRuntime.queryInterface(XPropertySet.class, mxMCF);

            // Get the default context from the office server.
            Object objectDefaultContext =
                xpropertysetMultiComponentFactory.getPropertyValue(
                    "DefaultContext");

            // Query for the interface XComponentContext.
            mxComponentContext = (XComponentContext) UnoRuntime.queryInterface(
                XComponentContext.class, objectDefaultContext);

            /* A desktop environment contains tasks with one or more
               frames in which components can be loaded. Desktop is the
               environment for components which can instanciate within
               frames. */
            mxComponentLoader = (XComponentLoader)
                UnoRuntime.queryInterface(XComponentLoader.class,
                    mxMCF.createInstanceWithContext(
                        "com.sun.star.frame.Desktop", mxComponentContext));

            // Query for an XMultiServiceFactory instance from the global
            // service manager
            if (mxMSF == null) {
                mxMSF = (XMultiServiceFactory)UnoRuntime.queryInterface(
                    XMultiServiceFactory.class,
                    mxComponentContext.getServiceManager());
            }
        }
        catch(Exception exception) {
            System.err.println(exception);
        }
    }


    /*
       The com.sun.star.text.MailMerge service is a new API introduced in
       OpenOffice.org 1.1. It provides programmatic access to the Tools/Mail 
Merge
       feature available via the OpenOffice.org 1.1 UI.

       As the feature is new to OpenOffice.org 1.1, it is not documented in the
       Developers Guide or in the API reference. It should be available once
       the OpenOffice.org 1.1 SDK is released

       We were able to find out how to use the API by reading the source code
       of the idl files for the MailMerge service:


http://api.openoffice.org/source/browse/api/offapi/com/sun/star/text/MailMerge.idl

       and also by looking at the tests that had been written for the
       service by the QA project:


http://qa.openoffice.org/source/browse/qa/qadevOOo/tests/java/mod/_sw/SwXMailMerge.java

       If all else fails then you can probably get some help on the
       [EMAIL PROTECTED] mailing list
    */
    public void doMerge() {

        Object mmservice = null;

        try {
            // Create an instance of the MailMerge service
            mmservice = mxMCF.createInstanceWithContext(
                "com.sun.star.text.MailMerge", mxComponentContext);
        }
        catch (Exception e) {
            System.err.println("Error getting MailMerge service: " + e);
            return;
        }

        // Get the XPropertySet interface of the mmservice object
        XPropertySet oObjProps = (XPropertySet)
            UnoRuntime.queryInterface(XPropertySet.class, mmservice);

        try {

            // Set up the properties for the MailMerge command
            oObjProps.setPropertyValue("DataSourceName", mDataSourceName);

            oObjProps.setPropertyValue("Command", mTableName);

            oObjProps.setPropertyValue("CommandType",
                new Integer(com.sun.star.sdb.CommandType.TABLE));

            oObjProps.setPropertyValue("OutputType",
                new Short(com.sun.star.text.MailMergeType.FILE));

            System.out.println("test");
            
            oObjProps.setPropertyValue("DocumentURL", mFileURL);
            
            System.out.println("test2 " + mFileURL);
            
            oObjProps.setPropertyValue("OutputURL",
"file:///app/supports/vf_openoffice/fichiers/fusion/");

            oObjProps.setPropertyValue("FileNamePrefix", "off.odt");


        } catch (Exception e) {
            System.err.println("Error setting MailMerge properties " + e);
            return;
        }

        // Get XJob interface from MailMerge service and call execute on it
        XJob job = (XJob) UnoRuntime.queryInterface(XJob.class, mmservice);

        try {
            for (int i=0; i<100; i++)
            {
                System.out.println("avant job");
                job.execute(new NamedValue[0]);
                System.out.println("après job");
            }
        }
        catch (com.sun.star.lang.IllegalArgumentException iae) {
            System.err.println("Caught IllegalArgumentException: " + iae);
        }
        catch (com.sun.star.uno.Exception e) {
            System.err.println("Caught UNO Exception: " + e);
        }
    }
}

---------------------------------------------------------------------
Please do not reply to this automatically generated notification from
Issue Tracker. Please log onto the website and enter your comments.
http://qa.openoffice.org/issue_handling/project_issues.html#notification

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to