Controlling WebBrowser in ATL window. How to free memory when the window is unloaded? I am stuck
I have a Win32 C ++ application. There is a _tWinMain (...) method with GetMessage (...) in the while loop at the end. Before GetMessage (...) I create a 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 don't create the main window, my application needs about 150KB in memory.
But when you create the main window using the WebBrowser control internally, the memory usage increases to 8500K.
But I want to dynamically unload the main window. My _tWinMain (...) keeps working! I'm unloading with
DestroyWindow(m_MainHwnd)
But the WebBrowser control will not unload and deallocate used memory!
The used application memory is still 8500K!
I can also get a WebBrowser instance or with some extra code WebBrowser HWND
IWebBrowser2* m_pWebBrowser2;
CAxWindow wnd = (CAxWindow)m_MainHwnd;
HRESULT hRet = wnd.QueryControl(IID_IWebBrowser2, (void**)&m_pWebBrowser2);
So I tried to free the memory used by the main window and WebBrowser control with (say experimental):
if(m_pWebBrowser2)
m_pWebBrowser2->Release();
DestroyWindow(m_hwndWebBrowser); //<-- just analogous
OleUninitialize();
No success.
I also created a wrapper class that creates the main window. I created a pointer and deallocated it 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, which is WebBrowser control and free up memory back to about 150K. Later I recreate the window. It dynamically loads and unloads the main window, depending on other commands.
Thanks!
Hello
Martin
a source to share
The memory is not always displayed exactly when you want it. There may be some things that the class does in the background that it must wait before the memory can be completely removed. It is also possible that memory has been freed, but the kernel is holding it as assigned to your process on the assumption that your process will probably want to use it anyway.
If you create another web browser window after you destroyed the previous one, will the memory move another 8350K or will it be more or less the same?
a source to share