PRB: MTS Event Log 4098 "Unexpected Object Reference Count" (259463)



The information in this article applies to:

  • Microsoft Transaction Server 2.0, when used with:
    • Microsoft Windows NT Server 4.0
    • Microsoft Windows NT Workstation 4.0

This article was previously published under Q259463

SYMPTOMS

Microsoft Transaction Server (MTS) may log the following informational event:
Unexpected object reference count. The object still had references after the run-time environment released its last reference. Unbind
(Package: PSLk108 OSEP) (ProgId: Project.Class) (CLSID: {EA6CD25E-2B12-11D3-8F30-0001FA328EF7}) (Interface: IUnknown) (IID: {00000000-0000-0000-C000-000000000046}) (Method: 2) (Microsoft Transaction Server Internals Information: File: d:\viper\src\runtime\context\ccontext.cpp, Line: 2807)

CAUSE

This log indicates that an object did not return 0 (zero) from the IUnknown::Release method when the MTS context wrapper was releasing it. This informational message indicates the possibility of a leak.

There are two possible reasons for this log:
  • Someone called AddRef on your component without releasing it. This may have been done without the context wrapper. As a result, an instance is left (hanging around--colloquial) in memory, which most likely contributes to a memory leak for the process. To fix this problem, you must find the offending code and correct it.
  • The component is not returning 0 (zero) from IUnknown. The object is released when it has a reference count of 0. The COM specification does not require this, and some tools (such as PowerBuilder) do not return 0 from the last Release.

    In this case, to stop the event log, you must wrap the objects in other components (such as Microsoft Visual Basic components) that return 0 from the Release call. The wrapping components must be installed in MTS, and the wrapped components, which must not be installed in MTS, must reside in the same apartment as the wrapping component.

RESOLUTION

To resolve this problem, track the usage of the component that is named in the error message after ProgID. Make sure that you use SafeRef when the component is handing out references to itself.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. In Visual Basic, create an ActiveX dynamic-link library (DLL). Name the project "MyRefcount" and the class "CMyRefcount".
  2. Add a reference to Microsoft Transaction Server Type library.
  3. Add the following code to CMyRefcount:
    Public Function GetMe() As Object
        Dim context As ObjectContext
    
        Set context  = GetObjectContext
    
        Set GetMeToo = Me 'should be SafeRef(Me)
        
        context.SetComplete
    End Function
    					
  4. Build MyRefcount. Under the Component tab of the Project Properties dialog box, click Binary compatibility in the Version Compatibility list. Add MyRefcount to a new MTS package.
  5. Create a Visual Basic Standard EXE.
  6. Add a reference to the MyRefcount project.
  7. Add a button to the form, and paste the following code in the handler:
    Private Sub Command1_Click()
        Dim c As MyRefcount.CMyRefcount
        Dim c1 As MyRefcount.CMyRefcount
        
        Set c = CreateObject("MyRefcount.CMyRefcount")
        
        Set c1 = c.GetMe
    End Sub
    					
  8. Compile and run the executable file. The above-mentioned message appears in the event log. This informational message appears only in MTS and not in COM+.

Modification Type:MajorLast Reviewed:2/1/2001
Keywords:kbDSupport kbprb KB259463