开发者

WebBrowser Control in ATL window. How to free up memory on window unload? I'm stuck

I have a Win32 C++ Application. There is the _tWinMain(...) Method with GetMessage(...) in a while loop at the end. Before GetMessage(...) I create the main window with

HWND m_MainHwnd = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_LAYERED, CAxWindow::GetWndClassName(), _TEXT("http://www.-website-.com"), WS_POPUP, 0, 0, 1024, 768, NULL, NULL, m_Instance, NULL);

ShowWindow(m_MainHwnd)

If I do not create the main window, my application needs about 150K in memory.

But with creating the main window with the WebBrowser Control inside, the memory usage increases to 8500K.

But, I want to dynamically unload the main window. My 开发者_JAVA技巧_tWinMain(...) keeps running! Im unloading with

DestroyWindow(m_MainHwnd)

But the WebBrowser control won't unload and free up it's memory used!

Application memory used is still 8500K!

I can also get the WebBrowser Instance or with some additional code the WebBrowser HWND

IWebBrowser2* m_pWebBrowser2;

CAxWindow wnd = (CAxWindow)m_MainHwnd;

HRESULT hRet = wnd.QueryControl(IID_IWebBrowser2, (void**)&m_pWebBrowser2); 

So I tried to free up the memory used by main window and WebBrowser control with (let's say it's experimental):

if(m_pWebBrowser2) 
   m_pWebBrowser2->Release();

DestroyWindow(m_hwndWebBrowser);  //<-- just analogous

OleUninitialize();

No success at all.

I also created a wrapper class which creates the main window. I created a pointer and freed it up with delete:

Wrapper* wrapper = new Wrapper();
//wrapper creates main window inside and shows it
//...do some stuff
delete(wrapper);

No success. Still 8500K. So please, how can I get rid of the main window and it's WebBrowser control and free up the memory, returning to about 150K. Later I will recreate the window. It's a dynamically load and unload of the main window, depending on other commands.

Thanks!

Regards

Martin


You have what is known as a reference leak. Before you call ::Release() on your IWebBrowser2*, see how many references are open. If it's not 1, then something else somewhere has a reference to your object.

Also, don't forget to IWebBrowser2::Quit() your control...


The memory isn't always released exactly when you want it to be. There may be some things that the class is doing in the background that it must wait for before the memory can be entirely deleted. Its also possible that the memory has been freed but the kernel holds it as assigned to your process under the assumption that your process will probably want to use it in a bit anyway.

If you create another web browser window after you've destroyed the previous does the memory jump up a further 8350K or does it stay more-or-less the same?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜