PRB: COM+ Instance Count Does Not Decrease When Called from .NET Application

Article translations Article translations
Article ID: 305823 - View products that this article applies to.
This article was previously published under Q305823
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

SYMPTOMS

When you call a COM+ or Microsoft Transaction Server (MTS) component from a .NET application, the object activates in the COM+ or MTS-hosted environment, but when the call completes, the object count does not decrease immediately. This is true even if the object is explicitly set to nothing (Visual Basic .NET) or null (C#) in the .NET client code.

CAUSE

This behavior can occur because the .NET application actually contains a reference to a wrapper, known as a runtime callable wrapper (RCW), which is responsible for managing reference counts on the COM+ or MTS component. This RCW is subject to .NET garbage collection semantics. Only when the RCW is "garbage collected" does it call the final release on the Component Object Model (COM) object. Garbage collection occurs only under memory pressure. Therefore, under simple test conditions, it is possible to observe an object activation remain alive indefinitely in Status view in COM+ Explorer.

RESOLUTION

To resolve this issue, explicitly release the COM object by calling the following method on the RCW from your .NET application:
System.Runtime.InteropServices.Marshal.ReleaseComObject(objref)
				
This method call forces the wrapper to release the reference. The wrapper is freed up when garbage collection occurs.

STATUS

This behavior is by design.

REFERENCES

For more information, browse to the following Microsoft Developer Network (MSDN) Web sites:
Marshal.ReleaseComObject Method
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.releasecomobject(VS.71).aspx
Introduction to COM Interop
http://msdn.microsoft.com/en-us/library/kew41ycz(VS.71).aspx
Microsoft .NET/COM Migration and Interoperability
http://msdn.microsoft.com/en-us/library/ms978506.aspx

Properties

Article ID: 305823 - Last Review: February 28, 2014 - Revision: 4.3
APPLIES TO
  • Microsoft Enterprise Services (included with the .NET Framework) 1.0
  • Microsoft COM+ 1.5
  • Microsoft COM+ 1.0
  • Microsoft Transaction Services 2.0
Keywords: 
kbnosurvey kbarchive kbprb kbsysadmin KB305823

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com