Microsoft KB Archive/275610

= FIX: Memory Leaks in Java/COM When You Use Variant or SafeArray Parameters =

Article ID: 275610

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine, when used with:
 * Microsoft Windows 2000 Standard Edition

-



This article was previously published under Q275610



SYMPTOMS
Applications that use Variant or SafeArray parameters in Java/Component Object Model (COM) methods may experience a memory leak. The symptoms include unbounded private byte and handle (semaphore) counts.



CAUSE
This is caused by a bug in the Windows 2000 Java/COM implementation of the Microsoft virtual machine (Microsoft VM). COM+ context objects that are associated with Variant and SafeArray objects are not freed, which causes unbounded memory and handle (semaphore) consumption.



RESOLUTION
To resolve this issue, install build 3318 or later of the Microsoft VM. For more information, visit the following Microsoft Web site:

http://www.microsoft.com/mscorp/java/

WARNING: After you install the updated Microsoft VM, you cannot uninstall it.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
These steps assume that you have the Microsoft Software Development Kit (SDK) for Java installed on your computer. You can download the Microsoft SDK from the following Microsoft Web site:

http://www.microsoft.com/mscorp/java/

These steps also assume that are you familiar with the Component Services administrative tool in Windows 2000.   Create a file named VariantLeakTest.java, and paste the following code: import com.ms.com.ComLib; import com.ms.com.Variant; import com.ms.lang.SystemX; import variantleakcomponent.VariantLeakComponent_Dispatch;

public class VariantLeakTest {   static void DoWork {       Variant                                     var; variantleakcomponent.VariantLeakComponent  disp;

var = new Variant( &quot;foo&quot; ); disp = new variantleakcomponent.VariantLeakComponent;

disp.MethodReceivingVariant( var );

var.VariantClear; ComLib.release( disp ); }

public static void main( String[] args ) throws Throwable {       ComLib.declareMessagePumpThread;

for( int iOuter = 0; iOuter < 100; iOuter++ ) {           for( int iInner = 0; iInner < 100; iInner++ ) {               DoWork; }

System.out.print( &quot;*&quot; ); SystemX.gc; }

System.out.println; System.out.print( &quot;press to exit&quot; ); System.in.read; } }                     Create a file named VariantLeakComponent.java, and paste the following code: import com.ms.com.Variant;

public class VariantLeakComponent {   public void MethodReceivingVariant( Variant var ) {   } }                     From a command prompt, type the following lines to build the sample files:

jvc /x- /nomessage VariantLeakComponent.java

javareg /register /class:VariantLeakComponent /clsid:{aa9161e0-43a8-4d58-b761-4412bbe23ff4} /progid:VariantLeakComponent /typelib:VariantLeakComponent.tlb /q

jactivex /javatlb /xi /d. VariantLeakComponent.tlb

jvc /x- /nomessage VariantLeakTest.java

 Use the Component Services administrative tool to create a COM+ application with library activation, and import the VariantLeakComponent component. From a command prompt, type the following line to run the sample:

jview VariantLeakTest

View the &quot;Mem Usage&quot; (Memory Usage) and &quot;Handles&quot; (Handles Count) columns in Task Manager.</li></ol>

<div class="references_section">