FIX: Memory Leaks in Java/COM When You Use Variant or SafeArray Parameters (275610)



The information in this article applies to:

  • Microsoft virtual machine, when used with:
    • the operating system: Microsoft Windows 2000

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: 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.

MORE INFORMATION

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: These steps also assume that are you familiar with the Component Services administrative tool in Windows 2000.
  1. 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( "foo" );
            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( "*" );
                SystemX.gc();
            }
    
            System.out.println();
            System.out.print( "press <enter> to exit" );
            System.in.read();
        }
    }
    					
  2. Create a file named VariantLeakComponent.java, and paste the following code:
    import com.ms.com.Variant;
    
    public class VariantLeakComponent
    {
        public void MethodReceivingVariant( Variant var )
        {
        }
    }
    					
  3. 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

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

    jview VariantLeakTest

    View the "Mem Usage" (Memory Usage) and "Handles" (Handles Count) columns in Task Manager.

REFERENCES

For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbBug kbfix kbJavaVM33xxfix kbOSWin2000fix KB275610