Can someone explain clearly what is the difference between
.Release()
and
->Release() on a CComPtr ?
To be precise how the memory management happens in either case?
Can someone explain clearly what is the difference between
.Release()
and
->Release() on a CComPtr ?
To be precise how the memory management happens in either case?
The operator-> function of CComPtr yields a raw interface pointer to the object being managed. (but see below)
So, calling ->Release() will release the object (i.e. decrement its internal reference count).
The .Release() function will call ->Release(), and make the smart pointer stop managing the raw interface pointer.
The latter is usually what you want to do. If you call ->Release() then smart pointer doesn't know this , and when the smart pointer's destructor runs, it will call ->Release() again which is bad (double release).
According to this page, recent versions of ATL actually have operator-> return a proxy class which hides AddRef and Release, so you should get a compilation error if you try ->Release(), instead of getting a double delete.