Skip to content

AddRef Release Semantics

Gregg Miskelly edited this page Jan 10, 2018 · 4 revisions

NOTE: This section applies only when consuming the Concord API from native code.

If you aren't familiar with COM, please read the intro documentation first.

The native Concord API adheres to standard COM conventions for AddRef/Release. If an object is returned as the return value, this is done without increasing the ref count on the object. If the object comes back as an out parameter, Release should be called. The Dispatcher will guarantee that any input object to a Concord interface method will stay valid until the implementer returns from the method. It will also guarantee that if an object provides an accessor method which returns another object, then this return value is immutable and doesn’t need to be AddRef’ed/Release’ed (though doing so will certainly not hurt anything). Examples to illustrate these rules:

    {
        DkmThread* pDkmThread = pDkmProcess->Thread();
        pDkmThread->Release(); // BUG: pDkmThread should not be Released
    }
    {
        DkmThread* pDkmThread;
        pDkmProcess->FindSystemThread(12, &pDkmThread);
    } // BUG: pDkmThread is leaked; pDkmThread->Release() must be called
    {
        // Correct, but the extra AddRef/Release that CComPtr will add isn't required
        // as long as the code isn't somehow releasing its reference to DkmProcess
        CComPtr<DkmThread> pDkmThread = pDkmProcess->Thread(); 
    }
Clone this wiki locally