Memory leak

  • Thread starter Thread starter eduard.antonyan
  • Start date Start date
E

eduard.antonyan

All I'm doing is going through the webpage and analyzing the data,
here's the outline of the code:

in OnDocumentComplete(LPCTSTR lpszURL)
{
IDispatch *pDispatch = GetHtmlDocument();
IHTMLDocument2 *pDoc;
IHTMLElement *pBody;
BSTR str;

pDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc);
pDispatch->Release();

pDoc->get_body((IHTMLElement **)&pBody);
pDoc->Release();

pBody->get_innerHTML(&str);
pBody->Release();

//---------------------------
// Analyze the str using wcsstr, Navigate2 depending on the results.
//---------------------------

SysFreeString(str);

CHtmlView::OnDocumentComplete(lpszURL);
}

The above results in a memory leak so what am I doing wrong?

I've tried calling CHtmlView::OnDocumentComplete(lpszURL) before I do
everything else and calling SysFreeString before doing Navigate2..
Can't think of anything else..:(
 
Hi eduard!
All I'm doing is going through the webpage and analyzing the data,
here's the outline of the code:

in OnDocumentComplete(LPCTSTR lpszURL)
{
IDispatch *pDispatch = GetHtmlDocument();
IHTMLDocument2 *pDoc;
IHTMLElement *pBody;
BSTR str;

pDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc);
pDispatch->Release();

pDoc->get_body((IHTMLElement **)&pBody);
pDoc->Release();

pBody->get_innerHTML(&str);
pBody->Release();

//---------------------------
// Analyze the str using wcsstr, Navigate2 depending on the results.
//---------------------------

SysFreeString(str);

CHtmlView::OnDocumentComplete(lpszURL);
}

The above results in a memory leak so what am I doing wrong?

HOW do you detect the memory leak?
Also be aware, that COM uses some "intelligent string pooling", so
"SysFreeString" does not necessarily release the memory!

Greetings
Jochen
 
Thanks for reply.

Well, using the obvious way - task manager (it can grow relatively
fast).. Or crt dumping.

So any way of checking whether SysFreeString releases the memory or
not? And also any ways of making it release the memory (or going around
that problem..:-\)?
 
Thanks for reply.

Well, using the obvious way - task manager (it can grow relatively
fast).. Or crt dumping.

So any way of checking whether SysFreeString releases the memory or
not? And also any ways of making it release the memory (or going around
that problem..:-\)?
 
Thanks, I'll check it out.

In task manager - yes, both actually.

Actually it seems to me that it leaks regardless of the code, i.e. just
the CHtmlWindow on its own. After a few hundred clicks it already
increases by ~40K (browsing the same pages btw, IE 7).
 
Back
Top