com pointers - check ref count

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?
LVL 45
AndyAinscowFreelance programmer / ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nonubikCommented:
For a tool, you can use BoundsChecker http://www.compuware.com/products/devpartner/bounds.htm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GreybirdCommented:
Or you could use the return values of AddRef and Release.
0
grg99Commented:
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.

0
novitiateCommented:
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.

_novi_
0
AxterCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.