Thread: DCOM Server - Memory keeps growing

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    5

    DCOM Server - Memory keeps growing

    I have a DCOM executable which is a server program written in C++. The client is a VB program which calls the methods from DCOM. When the first client makes the call to DCOM, the DCOM executable is started on the server side and its initial memory size is 20,000K. The memory keeps growing when ever any client calls a DCOM method. In C++ code, I call QueryInterface(...), AddRef() and I release pointer to Interface by calling Release(..), but the memory still keeps growing for every call to DCOM method.

    Why is this?

    When each client disconnect from DCOM server, the memory on server side is not release, but only when the last client disconnects, the DCOM executable is stopped which is fine.

    How can I keep the memory on server side not grow when clients are making calls to DCOM interface?

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    5
    Is there anybody that can help me with this.

    tx.

  3. #3
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Don't know DCOM, but used to do a bit of CORBA.

    Should the clients free their objects on the server before they disconnect?
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    6
    Need a little more info before I can offer any help. What does the object you implemented do? Was it implementated using ATL, MFC, or plain C++? Actual code would be great.

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    5
    The code is written using ATL COM Wizard.

    Here is the method that is called to connect to the DCOM server:

    STDMETHODIMP CConnector::Connect(long* User, IFeedback **MyFeedback, IGrid **TheGrid)
    {
    // TODO: Add your implementation code here
    MyGrid.QueryInterface(IID_IGrid, (void**)TheGrid);

    *User = MyGrid.CurrentUser++;

    MyGrid.AddRef();
    MyGrid.Feedbacks[*User].vt = VT_DISPATCH;
    IDispatch* pDisp;
    (*MyFeedback)->QueryInterface(IID_IDispatch, (void**)&pDisp);
    (*MyFeedback)->AddRef(); //mustafica: FIX
    (*MyFeedback)->Release(); //mustafica: FIX

    MyGrid.Feedbacks[*User].pdispVal = pDisp;

    return S_OK;
    }


    When the client calls the following method in DCOM Server the memory grows 200K first time and about 60K every other time. I think I properly release all the memory but then again you guys might know better.....here is the code:

    STDMETHODIMP CGrid::FindDefaultGroup(int Client, int Call_Type, int User)
    {
    // TODO: Add your implementation code here
    CdboFindDefaultGroup* DefaultGroup = new CdboFindDefaultGroup;

    DefaultGroup->m_calltype = Call_Type;
    DefaultGroup->m_client = Client;

    (*Feedbacks[User].pdispVal).QueryInterface(IID_IFeedback, (void**)TheFeedback);
    (*Feedbacks[User].pdispVal).AddRef(); //mustafica: FIX

    if (DefaultGroup->Open() == S_OK)
    {
    DefaultGroup->MoveFirst();
    (*TheFeedback)->DefaultGroup(DefaultGroup->m_colHuntGroup);
    }
    else
    (*TheFeedback)->DefaultGroup(0);

    DefaultGroup->Close();
    delete DefaultGroup;


    (*Feedbacks[User].pdispVal).Release();


    return S_OK;
    }


    I debugged the code and I notice that memory grows when QueryInterface function is called.

    Your help is appreciated.

    Thanks.

    Freestyle.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    6
    It difficult to be certain what the problem is based on what you posted (I'm still not exactly sure what the two methods are supposed to do) however I noticed one potential problem. You're calling AddRef() after QueryInterface() which usually isn't necessary. QueryInterface() automatically increments the reference count before returning the interface.

    Code:
    STDMETHODIMP CConnector::Connect(long* User, IFeedback **MyFeedback, IGrid **TheGrid)
    {
    // TODO: Add your implementation code here
    (IID_IGrid, (void**)TheGrid); //  <- Reference count incremented
    
    *User = MyGrid.CurrentUser++;
    
    MyGrid.AddRef();  //  <- Reference count incremented a second time
    MyGrid.Feedbacks[*User].vt = VT_DISPATCH;
    MyGrid.QueryInterface
    ...
    Assuming MyGrid is some flavor of smart COM pointer that calls Release() on the interface in the destructor (I don't see its definition) this methods returns without releasing all it's references to the interface. Is this desired?

    The same issue occurs in your CGrid::FindDefaultGroup() method.

    Try defining _ATL_DEBUG_INTERFACES. Defining it will cause ATL to dump reference count info to the Output window allowing you to trace each call to AddRef() and Release(). It will do this for every interface you implement. For example when MyGrid.QueryInterface() gets called for the first time ATL will output:

    1 > CGrid - IGrid

    The greater than sign means AddRef() was called. The digit one would be the current reference count. When Release() gets called you should get:

    0 < CGrid - IGrid

    The less than sign means Release() was called and the digit zero means no more references to that interface exist. All of your interfaces should *eventually* go to zero.
    Last edited by Solo; 10-25-2002 at 11:02 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  2. Novice Pointers/Class Question
    By C++Gamer in forum C++ Programming
    Replies: 8
    Last Post: 06-28-2006, 05:36 PM
  3. Memory Leak Help
    By (TNT) in forum Windows Programming
    Replies: 3
    Last Post: 06-19-2006, 11:22 AM
  4. Unicode vurses Non Unicode client server application with winsock2 query?
    By dp_76 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-16-2005, 07:26 AM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM