Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [platform-swt-dev] memory leak while using OLE automation

I am pasting the code in this mail.
(The application is  using OLE automation to convert Excel spreadsheets into
Text, using the SaveAs in MS-Excel.)
---------------------Code----------------
	Shell		shell;
	OleFrame	oleFrame;
	OleClientSite	oleClientSite;		
	OleAutomation	oleAutomation;

	int[]	ids, rgdid;
	Variant[] 	var;
	Variant		pvarResult;
	int	dispid;
	String[] arguments = new String[] {	"SaveAs",
	
"filename",
	
"fileformat"};


	shell	=	new Shell();
	oleFrame =	new OleFrame(shell, SWT.NO_BACKGROUND);
	
	String	outputFile = new String("outputFile.txt");
	String inputFile = new String("inputFile.xls");
	File outF = new File(outputFile);
	outF.delete();

	oleClientSite =
		new OleClientSite(oleFrame, SWT.NO_BACKGROUND, new
File(inputFile));
	oleAutomation = new OleAutomation(oleClientSite);


	ids = oleAutomation.getIDsOfNames(arguments);

	dispid = ids[0];
	rgdid = new int[] { ids[1], ids[2] };

	var 		= new Variant[2];
	var[0]	 	= new Variant(outputFile);
	var[1]		= new Variant(3);
	pvarResult 	= oleAutomation.invoke(dispid, var, rgdid);
	
	boolean result = pvarResult.getBoolean();
	
	var[0].getDispatch().Release();
	var[1].getDispatch().Release();
	pvarResult.getDispatch().Release();

	oleAutomation.dispose();
	oleFrame.dispose();
	oleClientSite.dispose();
	shell.dispose();

-----Original Message-----
From: Veronika Irvine [mailto:Veronika_Irvine@xxxxxxx]
Sent: Tuesday, November 05, 2002 10:26 AM
To: platform-swt-dev@xxxxxxxxxxx
Subject: RE: [platform-swt-dev] memory leak while using OLE automation



Please send code.  Please post it to this mailing list or enter a bug
report against Platform SWT with the code attached. (Please do not email it
directly to me as legally I am not allowed to review code that you would
not be willing to share in this forum).



 

                      "Gupta, Saurabh [IT]"

                      <saurabh.gupta@citigrou         To:
"'platform-swt-dev@xxxxxxxxxxx'" <platform-swt-dev@xxxxxxxxxxx>

                      p.com>                          cc:

                      Sent by:                        Subject: RE:
[platform-swt-dev] memory leak while using OLE automation

                      platform-swt-dev-admin@

                      eclipse.org

 

 

                      05/11/2002 09:51 AM

                      Please respond to

                      platform-swt-dev

 

 




I have tried the workaround that you have suggested for this leak.
I am calling getDispatch().Release() . This seems to work a little better
but still there are memory leaks.

Without the workaround I was able to run 57,000 iterations. After
implementing the workaround, I could go upto 60,000 iterations. But still
there appears to be a considerable memory leak problem. The JVM started
with
an intial 100Mb heap but after 60,000 iterations the process was taking
around 650Mb. When the tests went down with SWTException, the overall mem.
usage decreased considerably.

If you want I can send the code.

thanks



-----Original Message-----
From: Veronika Irvine [mailto:Veronika_Irvine@xxxxxxx]
Sent: Friday, October 25, 2002 10:37 AM
To: platform-swt-dev@xxxxxxxxxxx
Subject: Re: [platform-swt-dev] memory leak while using OLE automation



The correct way to release the resources for OleAutomation and
OleClientSite is to call "dispose". The dispose method will manage the
reference count.

 The "disposeCOMInterfaces" is called when the reference count for the
related interfaces is 0.  You do not need to call it yourself.

There is a weakness in my Variant story however.  Variant really should
have a dispose method too.

The reason is that when you get a Variant with IDispatch or IUnknown
inside, Variant calls AddRef on the interface (in setData).  Then when you
call getAutomation, another AddRef is called on the IDispatch interface.
The OleAutomation.dispose calls Release once but there is still an
outstanding AddRef to be cancelled.  The Variant.dispose method should take
care of this.  As a workaround, you could call Variant.getDispatch and call
Release on the IDispatch object.

I will add the dispose method to Variant in 2.1 (see bug report
http://dev.eclipse.org/bugs/show_bug.cgi?id=25383).

You could also check out the ref count for OleClientSite (add a print
statement in OleClientSite.Release). It is possible that the ref count is
not going down to zero which would result in the vtables for the COM
interfaces being leaked (this would leak about 156 bytes for each
OleClientSite).





                      "Gupta, Saurabh [IT]"

                      <saurabh.gupta@citigrou         To:
platform-swt-dev@xxxxxxxxxxx

                      p.com>                          cc:

                      Sent by:                        Subject:
[platform-swt-dev] memory leak while using OLE automation

                      platform-swt-dev-admin@

                      eclipse.org





                      25/10/2002 09:36 AM

                      Please respond to

                      platform-swt-dev








Hi,
I am using the OLE Automation classes in SWT to convert some of my Excel
files into Text delimitted files, and I am finding that there is a
potential
memory leak problem. The JVM crashes after 60,000 iterations with the
exception
org.eclipse.swt.SWTException: Failed to create Ole Client. result =
-2146959355
at org.eclipse.swt.ole.win32.OLE.error(OLE.java:291)
at org.eclipse.swt.ole.win32.OleClientSite.<init>(OleClientSite.java:186)

I have checked all the dispose() and garbage disposal mechanisms for
OleClientSite, OleAutomation, Shell and other classes.

Does anyone know if this is a known bug??
Is the standard way to dispose OleClientSite is to just call dispose() ??

Also, one interesting thing that I found in the SWT code was that there is
a
protected method in OleClientSite named disposeCOMInterfaces() does all the
disposing related to ceratin member COMObject "iUnknown, iOleInPlaceSite".
I do not know if I should be calling disposeCOMInterfaces() as well , (but
I
can't because it is protected)??

any help is appreciated.

thanks
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev




_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev




_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top