PRB: COM+ Instance Count Does Not Decrease When Called from .NET Application (305823)
The information in this article applies to:
- Microsoft Enterprise Services (included with the .NET Framework) 1.0
- Microsoft COM+ 1.5
- Microsoft COM+ 1.0
- Microsoft Transaction Server 2.0
This article was previously published under Q305823 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. STATUSThis
behavior is by design.REFERENCES For more information, browse to the following Microsoft
Developer Network (MSDN) Web sites:
Modification Type: | Major | Last Reviewed: | 9/24/2003 |
---|
Keywords: | kbprb kbSysAdmin KB305823 |
---|
|