Consider the following scenario:
Note Because ActiveX controls consume more memory than native HTML elements, the memory leak is more obvious if one of the elements in the collection is an ActiveX control.
For example, a memory leak occurs when you use the following C++ code in a function of a web browser control host application. In this situation, a large volume of memory is leaked if one of the elements on the webpage is an ActiveX control.
- You develop a web browser control host application or an ActiveX control.
- The application or ActiveX control references the enumerator object from a collection interface of an HTML page. To create this functionality, see the following guidelines:
- In C++, the enumerator is obtained by calling the get__newEnum function of a collection interface. An example of a collection interface is IHTMLElementCollection, and this is usually obtained by calling IHTMLDocument2::get_all.
- In Visual Basic, this step is performed behind the scenes in a foreach construct over a collection (for example, the document.all collection).
- You run the application on a computer that has Internet Explorer 10 installed.
Note Because ActiveX controls consume more memory than native HTML elements, the memory leak is more obvious if one of the elements in the collection is an ActiveX control.
For example, a memory leak occurs when you use the following C++ code in a function of a web browser control host application. In this situation, a large volume of memory is leaked if one of the elements on the webpage is an ActiveX control.
void CEnumLeakDlg::OnBnClicked()
{
IDispatch* pDocDisp = m_web.get_Document();
IHTMLDocument2* pDoc = NULL;
HRESULT hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
IHTMLElementCollection* pElColl = NULL;
hr = pDoc->get_all(&pElColl);
IUnknown* pEnum = NULL;
hr = pElColl->get__newEnum(&pEnum);
pEnum->Release();
pElColl->Release();
pDoc->Release();
pDocDisp->Release();
}