ICountedPointerTo is a templatized "smart pointer" class which mimics a C++ pointer and can be used for reference counting both IMRefCounted objects and objects that do not descend from IMRefCounted.
ICountedPointerTo automatically calls addRef and removeRef
on the object to which it points. In contrast, you have to
remember to call addRef and removeRef
yourself whenever you create and throw away a regular C++ pointer
to a reference counted object. This is a large source of
potential errors. If you forget to call removeRef,
your program will leak memory. If you forget to call addRef,
an object might be deleted while you are using it.
When you use ICountedPointerTo for reference counting objects that do not descend from IMRefCounted, you must follow some rules that are described in the chapter Using Counted Pointers.
![]()
Using Counted
Pointers
Using Reference
Counted Objects