Community
Participate
Working Groups
Posted to swt mailing list by Gupta, Saurabh [IT] (saurabh.gupta@citigroup.com): I could go up to 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. 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();
I ran the following code in Eclipse 2.1 (I200302050800). The memory grew to about ~13,400K and then remained constant - going up slightly then coming back down. I am closing this bug report as fixed in 2.1. Please reopen if you are still having this problem in 2.1. My example is somewhat modified from yours because when you try to cooerce a variant into an invalid type, an exception is thrown. Also, disposing the shell will dispose all the children below it so disposing the ole frame and client site is unneccessary. Variant now has a dispose method to free resources. In your case, this will have no effect because the Variant only keeps the Java resources around - memory is released immediately. public class Bug25736 { public static void main(String[] args) { Display display = new Display(); for (int i = 0; i < 60000; i++) { run(display); if (i % 1000 == 0) System.out.println("loop "+i); } } static void run(Display display) { Shell shell = new Shell(display); OleFrame oleFrame = new OleFrame(shell, SWT.NONE); String inputFile = new String("C:\\inputFile.xls"); OleClientSite oleClientSite = new OleClientSite(oleFrame, SWT.NO_BACKGROUND, new File(inputFile)); OleAutomation oleAutomation = new OleAutomation(oleClientSite); String[] arguments = new String[] { "SaveAs", "filename", "fileformat" }; int[] ids = oleAutomation.getIDsOfNames(arguments); int dispid = ids[0]; int[] rgdid = new int[] { ids[1], ids[2] }; Variant[] var = new Variant[2]; String outputFile = new String("C:\\outputFile.txt"); File outF = new File(outputFile); outF.delete(); var[0] = new Variant(outputFile); var[1] = new Variant(3); Variant pvarResult = oleAutomation.invoke(dispid, var, rgdid); if (pvarResult.getType() != OLE.VT_EMPTY) { boolean result = pvarResult.getBoolean(); } var[0].dispose(); var[1].dispose(); pvarResult.dispose(); oleAutomation.dispose(); shell.dispose(); } }