Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


com pointers - check ref count

Posted on 2005-03-06
Medium Priority
Last Modified: 2013-11-25
With com pointer one should match calls that increment the ref count with an equal number to decrement the ref count.  Is there a tool/setting that one can use to check that the app is actually doing that correctly?
Question by:AndyAinscow
LVL 16

Accepted Solution

nonubik earned 1500 total points
ID: 13474742
For a tool, you can use BoundsChecker http://www.compuware.com/products/devpartner/bounds.htm

Expert Comment

ID: 13475128
Or you could use the return values of AddRef and Release.
LVL 22

Expert Comment

ID: 13475875
Ah, in general, no.

     An app could keep a pointer, or copy it to another variable, and "forget" to increment the reference count.  Or it could exit a block of code and forget to decrement it.

There are tools to peek at the reference count at any time, but that just tells you what the current count is, not where the app went wrong in counting up or down.


Expert Comment

ID: 13476707
ATL smart pointers are the best way to handle reference count. As such I have not seen any tool doing this.

_COM_SMARTPTR_TYPEDEF(IMyInterface, __uuidof(IMyInterface));

will create a IMyInterfacePtr, smart pointer for you.

LVL 30

Expert Comment

ID: 13477509
I recommend using CComQIPtr, which encapsulates the call to AddRef and Release calls.

When the CComQIPtr object goes out of scope, it calls Release automatically.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question