Re: Do I need to call Release on smart pointer
Hi,
I have the following question. Thanks.
1. How do I figure out if a Microsoft SDK function return AddRef'd
pointers, e.g GetHtmlDocument()?
2. What's the consequence if I don't call Release? Is it memory leak? I
have the following code using GetHtmlDocument(), but I didn't use
Release, the program runs fine.
IHTMLDocument2 *document;
LPDISPATCH lpDispatch = GetHtmlDocument();
ASSERT(lpDispatch);
//get html document from IDispatch
LRESULT hr=lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)
&document);
WriteToDocument( document, xmlStr );
Jean
Jeff Partch [MVP] wrote:
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:%23qOuKeKhGHA.4304@TK2MSFTNGP05.phx.gbl...
With apologies and hesitation... Doesn't it depend on whether the
OtherFunc1 and/or OtherFunc2 AddRef the interface pointers they
return?
Well, I assumed OtherFunc1 and OtherFunc2 are correctly written. They
should return either a non-AddRef'ed raw pointer, or a smart pointer.
More apologies, but the reason I asked is that I routinely encounter wizard
generated wrappers which are keen to expose methods like: LPDISPATCH
GetHtmlDocument() -- that do return AddRef'd pointers, so in a function
like...
VOID CSomeClass::SomeFunc(VOID)
{
ISmartPointer p = m_someWrapper.GetSomeDispatch();
}
...you can expect the ref count to go up, up and up.
--
Jeff Partch [VC++ MVP]