none
ServicedComponent and # of CCWs RRS feed

  • Question

  • I am writing a native client application which calls a few .Net ServicedComponent. The client application will loop millions of times in a piece of code that will create an object (from ServicedComponent), make a method call, dispose the object and release all references.

    When I run the application, I notice that the # of CCWs increases forever. The process eventually runs out of memory. If I run the same code as a COM component (not in COM+, not a ServicedComponent), it behaves well (CCWs are cleaned by GC). However, the system I am integrating to is already build in COM+ and there is no way I can avoid it at this point.

    There must be something I am missing. Can anyone help?

    I created a simplified sample that exhibits the behavior I described. Here is the C code for the client :

    int

     

     

    _tmain(int argc, _TCHAR* argv[])
    {
       HRESULT hr;
       IMyInterface *pMyInterface = NULL;
       IDisposable *pDispose = NULL;
       long i;

       hr = CoInitialize(NULL);

       for(i=0; i<1000000; i++)
       {
          hr = CoCreateInstance(CLSID_MyClass1, NULL, CLSCTX_INPROC_SERVER, IID_IMyInterface, (void **)&pMyInterface);
          hr = pMyInterface->MyMethod2();
          hr = pMyInterface->QueryInterface(IID_IDisposable, (
    void **)&pDispose);
          hr = pDispose->Dispose();
          pDispose->Release();
          pMyInterface->Release();
       }
       CoUninitialize();
       return 0;
    }

    Here is the VB.NET ServicedComponent source code (simplified, with same bad behavior) :

    Namespace

     

     

    MyNamespace
       <
    ComVisible(True), InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("B7473470-75CC-4292-BDCD-6F300D5CAC63")> _
       Public Interface IMyInterface
          Sub MyMethod2()
       End Interface

       <Transaction(TransactionOption.RequiresNew), _
       JustInTimeActivation(True), _
       Synchronization(SynchronizationOption.RequiresNew), _
      
    ClassInterface(ClassInterfaceType.None), _
      
    EventTrackingEnabled(True), _
      
    ProgId("MyCOMPlusComponent.MyClass1"), _
      
    ComVisible(True), _
      
    Guid("F55B3A52-DEF1-4FF0-8D0B-8365932BE3F6")> _
      
    Public Class MyClass1
          Inherits ServicedComponent
         
    Implements IMyInterface

          Public Sub MyMethod2() Implements IMyInterface.MyMethod2
            
    Dim str As String

             str = "Hello World!"
            
    ContextUtil.SetComplete()
          End Sub
       End Class
    End
    Namespace

    Thanks in advance!
    Alexandre

    Saturday, December 18, 2010 1:15 AM

Answers

  • Hi, Reviewed the code snippet and the question.

    Based on the issue that you are seeing, we will have to get the data and analyze it which will take some time to investigate how these methods are behaving and why the CCWs are getting cleaned up.

    My suggestion is to see about what options to check out. Here is some info for more in depth level

    into the problems through support.

    There are various support options such as advisory and per issue. Please visit the below link to see

    the various paid

    support options that are available to better meet your needs.

    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone


    bill boyce
    • Marked as answer by Cookie Luo Monday, December 27, 2010 9:47 AM
    Thursday, December 23, 2010 4:27 PM
    Moderator

All replies

  • After more testing, the CCWs leak happens only when I call ContextUtil.SetComplete (or any method that modify the consistent or done bits). If I change MyMethod2 for the code below, the CCWs are cleaned by the GC.

    <AutoComplete(True)> _
    Public Sub MyMethod2() Implements IMyInterface.MyMethod2
       Dim str As String
       str = "Hello World!"
    End Sub

    Can anyone explain why the ContextUtil.SetComplete method leaks those CCWs?

    Thank you.
    Alexandre

    Monday, December 20, 2010 2:35 AM
  • Hi, Reviewed the code snippet and the question.

    Based on the issue that you are seeing, we will have to get the data and analyze it which will take some time to investigate how these methods are behaving and why the CCWs are getting cleaned up.

    My suggestion is to see about what options to check out. Here is some info for more in depth level

    into the problems through support.

    There are various support options such as advisory and per issue. Please visit the below link to see

    the various paid

    support options that are available to better meet your needs.

    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone


    bill boyce
    • Marked as answer by Cookie Luo Monday, December 27, 2010 9:47 AM
    Thursday, December 23, 2010 4:27 PM
    Moderator
  • Hi,

    My customer has a MS-Premier support contract and I have already recommended that they open a case with Premier. I provided all the information they need to do so, but they might wait after the holidays before they open the case.

    I will get back here to share the answer/solution when we get this working.

    Thanks for your time answering this thread.

    Alexandre

    Thursday, December 23, 2010 4:52 PM
  • This is a confirmed issue in .Net Framework 2.0. The issue is not present in .Net Framework 4.0.
    Wednesday, February 2, 2011 2:45 AM