Question

Memory Leaks found in an MFC / COM / GDI application (HTML thumbnail image capture class)

Asked by: DrivenX

Hi, I'm new to Experts-Exchange and this would be my first question.  Thanks in advance, please let me know if the format of my question can be improved to make it easier for the experts :)

I am a beginner in using MFC and COM and I am following up on a windows application.  One of the features is to be able to generate an image from a URL.  I have included the code of the function in the thumbnail capture class (CCreateHTMLImage).  (The original source for this code can be found at http://www.codeproject.com/KB/IP/htmlimagecapture.aspx - I have modified the CreateImage function, integrating with IECapt's SaveSnapShot method found here http://iecapt.sourceforge.net/ ).

When the user chooses to generate a thumbnail capture of a webpage, the application will do the following routine inside a CView derived class:
m_pHTMLImage is a pointer set to NULL initially

            if(m_pHTMLImage == NULL) {
                  OutputDebugString("Initializing m_pHTMLImage\n");
                  m_pHTMLImage = new CCreateHTMLImage();
                  m_pHTMLImage->Create(this);
            }

            if(!m_pHTMLImage -> CreateImage(_T("http://")+URL, AppDirectory + _T("\\temp.jpg"), CSize(1024, 768), CSize(360,300)))
                  return;

            It will then call a function LoadPic(AppDirectory + _T("\\temp.jpg"));

LoadPic(CString PicPath)
{
      CFile file;
      if(!file.Open(PicPath, CFile::modeRead|CFile::shareDenyWrite|CFile::typeBinary))
            return FALSE;
      if(m_dwPicLen != 0)
            delete[] m_BPicData; //if pic already exists, clear and load new data
      m_dwPicLen = (DWORD)(file.GetLength());                                                
      if(!m_Pic.Load(file.GetFilePath()))
            return FALSE;
      m_bIsPic = TRUE; //set display mode to pic
      m_BPicData = new BYTE[m_dwPicLen];
      file.Read(m_BPicData, m_dwPicLen);
      file.Close();
      return TRUE;
}

the memory usage jumps from ~10,000K to ~100,000K, should it be using this much memory?
subsequent calls to this routine of generating an image will raise mem usage by ~10,000K
I only create one instance of CCreateHTMLImage and will do the following routine when the application closes in the CView class' destructor

      if(m_pHTMLImage) {  
            m_pHTMLImage->DestroyWindow();  
            delete m_pHTMLImage;  // EL
            m_pHTMLImage = NULL;  
      }

Are there any problems regarding the Allocation and Release of Interfaces or in Getting and Releasing/Deleting DCs in the CreateImage Function? would i have to delete or release hdcMain?

I have used PurifyPlus and I have attached the results as images.
The leaks seem to come from DLLs, does it mean that it is not related to the classes I am working on?

More recent debug results are from boundschecker.

I am also getting many many of the following errors when i generate a thumbnail
First-chance exception at 0x30195840 in czWeb.exe: 0x80000001: Not implemented.
First-chance exception at 0x30195196 in czWeb.exe: 0x80000001: Not implemented.
Any idea what could generate these errors ?

Any help would be greatly appreciated.  Please let me know if anything was unclear or if you need more information

Thanks

BOOL CCreateHTMLImage::CreateImage(LPCTSTR szSrcFilename, LPCTSTR szDestFilename, CSize srcSize, CSize outputSize)
{
	USES_CONVERSION;
	ASSERT(GetSafeHwnd());
	ASSERT(IsWindow(GetSafeHwnd()));
	ASSERT(szSrcFilename);
	ASSERT(AfxIsValidString(szSrcFilename));
	ASSERT(szDestFilename);
	ASSERT(AfxIsValidString(szDestFilename));
 
	CRect rect(CPoint(0, 0), srcSize);
 
	//	The WebBrowswer window size must be set to our srcSize
	//	else it won't render everything
	MoveWindow(&rect);
	m_pBrowserWnd.MoveWindow(&rect);
 
	COleVariant	  vUrl(szSrcFilename, VT_BSTR),
				  vFlags(long(navNoHistory | navNoReadFromCache | navNoWriteToCache), VT_I4),
				  vNull(LPCTSTR(NULL), VT_BSTR);
	COleSafeArray vPostData;
 
	if (m_pBrowser->Navigate2(&vUrl, &vFlags, &vNull, &vPostData, &vNull) == S_OK)
		//	We have to pump messages to ensure the event handler (DocumentComplete)
		//	is called.
		RunModalLoop();
	else
		return FALSE;
 
//	We only get here when DocumentComplete has been called, which calls EndModalLoop
	//	and causes RunModalLoop to exit.
 
 
	IHTMLDocument3* pDocument3 = NULL;
        IHTMLDocument2* pDocument  = NULL;
        IHTMLElement2* pElement2   = NULL;
        IHTMLElement* pElement     = NULL;
        IViewObject2* pViewObject  = NULL;
        IDispatch* pDispatch       = NULL;
        //IDispatch* pWebBrowserDisp = NULL;
 
        HRESULT hr;
        long bodyHeight;
        long bodyWidth;
        long rootHeight;
        long rootWidth;
        long height;
        long width;
 
        hr = m_pBrowser->get_Document(&pDispatch);
		if (hr == S_OK) {  // Need to release pDispatch
 
			hr = pDispatch->QueryInterface(IID_IHTMLDocument2, (void**) &pDocument);
			if (hr == S_OK) {  // Need to release pDocument
 
				hr = pDocument->get_body(&pElement);
				if (hr == S_OK) {  // Need to release pElement
 
					hr = pElement->QueryInterface(IID_IHTMLElement2, (void**) &pElement2);
					if (hr == S_OK) {  // Need to release pElement2
 
						hr = pElement2->get_scrollHeight(&bodyHeight);
						if (FAILED(hr))
							return true;
 
						hr = pElement2->get_scrollWidth(&bodyWidth);
						if (FAILED(hr))
							return true;
 
						pElement2->Release();
					}
					pElement->Release();
				}
				pDocument->Release();
			}
 
			hr = pDispatch->QueryInterface(IID_IHTMLDocument3, (void**) &pDocument3);
			if (hr == S_OK) {  // Need to release pDocument3
 
				hr = pDocument3->get_documentElement(&pElement);
				if (hr == S_OK) {  // Need to release pElement
 
					hr = pElement->QueryInterface(IID_IHTMLElement2, (void**) &pElement2);
					if (hr == S_OK) {  // Need to release pElement2
 
						hr = pElement2->get_scrollHeight(&rootHeight);
						if (FAILED(hr))
							return true;
 
						hr = pElement2->get_scrollWidth(&rootWidth);
						if (FAILED(hr))
							return true;
						pElement2->Release();
					}
					pElement->Release();
				}
				pDocument3->Release();
			}
 
 
			width = bodyWidth;
			height = rootHeight > bodyHeight ? rootHeight : bodyHeight;
 
			MoveWindow(0, 0, width, height, TRUE);      
			::MoveWindow(m_pBrowserWnd.GetSafeHwnd(), 0, 0, width, height, TRUE);
 
			hr = m_pBrowser->QueryInterface(IID_IViewObject2, (void**) &pViewObject);
			if (hr == S_OK) {  // Need to release pViewObject
				BITMAPINFOHEADER bih;
				BITMAPINFO bi;
				RGBQUAD rgbquad;
 
				ZeroMemory(&bih, sizeof(BITMAPINFOHEADER));
				ZeroMemory(&rgbquad, sizeof(RGBQUAD));
 
				bih.biSize          = sizeof(BITMAPINFOHEADER);
				bih.biWidth         = width;
				bih.biHeight        = height;
				bih.biPlanes        = 1;
				bih.biBitCount      = 24;
				bih.biClrUsed       = 0;
				bih.biSizeImage     = 0;
				bih.biCompression   = BI_RGB;
				bih.biXPelsPerMeter = 0;
				bih.biYPelsPerMeter = 0;
 
				bi.bmiHeader = bih;
				bi.bmiColors[0] = rgbquad;
 
				CDC* dc = GetDC();
				HDC hdcMain = *dc;
 
				if (!hdcMain)
					return true;
 
				HDC hdcMem = CreateCompatibleDC(hdcMain);
 
				if (!hdcMem)
					return true;
 
				char* bitmapData = NULL;
				HBITMAP hBitmap = CreateDIBSection(hdcMain, &bi, DIB_RGB_COLORS, (void**)&bitmapData, NULL, 0);
 
				if (!hBitmap) {
					// TODO: cleanup
					return true;
				}
 
				// Save original bitmap, note this is needed to be reselected to preven GDI resource leak // EL
				HGDIOBJ oldHBitmap = GetCurrentObject(hdcMem, OBJ_BITMAP);
				if(oldHBitmap == NULL) {
					OutputDebugString("GetCurrentObj failed\n");
					return true;
				}
 
				SelectObject(hdcMem, hBitmap);
 
				RECTL rcBounds = { 0, 0, width, height };
				hr = pViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, hdcMain, hdcMem, &rcBounds, NULL, NULL, 0);
				if (SUCCEEDED(hr)) {
					CImage image;
					image.Create(outputSize.cx, outputSize.cy, 24);
					CImageDC imageDC(image);
					::StretchBlt(imageDC, 0, 0, outputSize.cx, outputSize.cy, hdcMem, 0, 0, width, height, SRCCOPY);
					//::BitBlt(imageDC, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);
					image.Save(szDestFilename);
				}
				
				SelectObject(hdcMem, oldHBitmap);
				DeleteObject(hBitmap);
				DeleteDC(hdcMem);
				//DeleteDC(hdcMain);
				ReleaseDC(dc);
				pViewObject->Release();
			}
			pDispatch->Release();
		}
		return true;
 
}
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:

Select allOpen in new window

  • bc1.jpg
    • 134 KB

    BC - Memory Leaks

  • bcsummary.jpg
    • 74 KB

    Summary of results from BoundsChecker

  • purify4.jpg
    • 463 KB

    PurifyPlus Results, Memory leak information 3

  • purify3.jpg
    • 446 KB

    PurifyPlus Results, Memory leak information 2

  • purify2.jpg
    • 472 KB

    PurifyPlus Results, Memory leak information 1

  • bc3.jpg
    • 60 KB

    BC - Errors

  • bc2.jpg
    • 264 KB

    BC - Other Leaks

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. MFC CString Implementation
    I have read a few magazine articles on how the MFC CString works. I use it frequently and understand it well, but I was wondering if there is a way I can view the actual source code (.cpp file) to see some of the implementation details.
  2. Using MFC's CString class without MFC
    Is there any way to use the CString class without doing an MFC program. I would like to use the class in my standard Win32 program, but the compiler does not seem to want to let me (Says that you cannot include windows.h along with that header file). Is there any way around...
  3. CString in non MFC application !
    is it possible to use class CString in an non MFC application ?
  4. MFC on Unix
    Is there a public domain implementation of MFC for Unix? I am interested mainly in CFile, CString, CPtrList, CPtrArray, CTime and few other classes.
  5. MFC with ADO
    I am trying to build a database app using ADO and at the same time using MFC classes like CString to do a lot of the work. The compiler does not like this and gives an error saying that MFC apps cannot include windows.h. I have tried everything to get rid of this error but i...
  6. AGAIN:: CString object and MFC !!
    I understand.. The MFC is a VERY HUGE class, which has a lot of things in it, which mainly I don´t need.. A bit around my program: I have to make a DLL, which will be called in ASP-Scripts, for doing many Server-Jobs (uploading, Shop, ...) I´m still busy with the bas...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: evilrixPosted on 2008-01-31 at 13:51:31ID: 20791603

The following info may help you to track down if you have any heap related memory leaks.

You can use _CrtSetDbgFlag to enable CRT heap allocation debugging. This should be at the very start of your program.
E.g. _CrtSetDbgFlag ( _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) | _CRTDBG_LEAK_CHECK_DF );
http://msdn2.microsoft.com/en-us/library/974tc9t1(VS.80).aspx

You can use _CrtDumpMemoryLeaks to generate an error report if the application failed to free all the memory it allocated. This should be at the very end of your program.
http://msdn2.microsoft.com/en-us/library/d41t22sb(VS.80).aspx

Use can use _CrtSetBreakAlloc or _crtBreakAlloc to set break points where specific heap is allocated (as reported by CrtDumpMemoryLeaks) so that you can see where the problem starts
http://support.microsoft.com/kb/151585

Memory leak detection and isolation: http://msdn2.microsoft.com/en-us/library/x98tx3cf(VS.80).aspx

-Rx.
   

 

by: jkrPosted on 2008-01-31 at 13:58:34ID: 20791671

1st of all, there are a lot of return paths where I miss 'Release()' on active objects like

                               if(oldHBitmap == NULL) {
                                        OutputDebugString("GetCurrentObj failed\n");
                                        return true;

you might want to use scoped smart pointers instead

#import "C:\winnt\system32\mshtml.tlb" // location of mshtml.tlb
 
using namespace MSHTML;
 
        IHTMLDocument3Ptr pDocument3 = NULL;
        IHTMLDocument2Ptr pDocument  = NULL;
        IHTMLElement2Ptr pElement2   = NULL;
        IHTMLElementPtr pElement     = NULL;
        IViewObject2Ptr pViewObject  = NULL;
        IDispatchPtr pDispatch       = NULL;
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: DrivenXPosted on 2008-01-31 at 16:22:56ID: 20793002

Thanks for the replies evilrix, jkr

I actually didnt get any memory leaks on a good run of the program.
But if i try to generate two images in quick succession i get the dump in the attached file, i will try to investigate.
Was wondering if a program that runs depending on user interaction would affect the use of _CrtSetBreakAlloc or _crtBreakAlloc.  Would the user have to do the same sequence of events, otherwise it may not be the same block of memory allocated the next time it is run?

jkr, I will look into smart pointers, do you have any recommendations on readings?  Thanks for the headsup on the return paths.

Am I doing the releasing and deleting of the DCs and the hBitmap correctly?  Im concerned about HDC hdcMain

Thanks

 

by: jkrPosted on 2008-01-31 at 19:10:10ID: 20793786

>>Was wondering if a program that runs depending on user interaction would
>>affect the use of _CrtSetBreakAlloc or _crtBreakAlloc.

Only the debug build. Anyway, these two functions won't get you any further anyway when you already have Purify. I am more acquainted with BoundsChecker, but Purify also should be able to give you more details about the allocations.

 

by: DrivenXPosted on 2008-01-31 at 22:39:52ID: 20794633

How would I go about tracking down the problems with the allocations in bounds checker?
such as in bc1.jpg in mytilus.dll, i cant seem to find anymore detail than just the .dll information
thanks

 

by: evilrixPosted on 2008-02-01 at 00:03:21ID: 20794871

Did you see in the links I provided that you can set break points at the point where the leaked resource is allocated? The debugger will kick in (if run with debugger enabled) at the point of allocation. You'll can then track the code path (by stepping through it for example) to see where it's going wrong, for example returning without releasing as jkr advised above. Although Purify or bounds checker can provide metrics to help track these issues down I've found, from experience, it's often necessary to follow the code to get an idea of exactly what is happening. Somethings it can be a time consuming process. To be honest, prevention is always better that cure so ubiquitous use of the RAII idiom should be adopted -- as jkr intimated, consider using smart pointers.

http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization

 

by: DrivenXPosted on 2008-02-01 at 11:16:15ID: 20799657

Thanks evilrix and jkr
Sorry if it seemed I just wanted a quick solution to this.  I know I'll have to do some work and ill set the break points after getting the smart pointers working.

I'm attempting to use smart pointers here:

      CComPtr<IHTMLDocument3> pDocument3;
        CComPtr<IHTMLDocument2> pDocument;
        CComPtr<IHTMLElement2> pElement2;
        CComPtr<IHTMLElement> pElement;
        CComPtr<IViewObject2> pViewObject;
        CComPtr<IDispatch> pDispatch;
        //IDispatch* pWebBrowserDisp = NULL;

        HRESULT hr;
        long bodyHeight;
        long bodyWidth;
        long rootHeight;
        long rootWidth;
        long height;
        long width;

        hr = m_pBrowser->get_Document(&pDispatch);

        if (FAILED(hr))
            return true;

        hr = pDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument);

        if (FAILED(hr))
            return true;

        hr = pDocument->get_body(&pElement);

        if (FAILED(hr))
            return true;

        hr = pElement->QueryInterface(IID_IHTMLElement2, (void**)&pElement2);

        if (FAILED(hr))
            return true;

        hr = pElement2->get_scrollHeight(&bodyHeight);

        if (FAILED(hr))
            return true;

        hr = pElement2->get_scrollWidth(&bodyWidth);

        if (FAILED(hr))
            return true;

        hr = pDispatch->QueryInterface(IID_IHTMLDocument3, (void**)&pDocument3);

        if (FAILED(hr))
            return true;

        hr = pDocument3->get_documentElement(&pElement);   // <----------- here

        if (FAILED(hr))
            return true;

        hr = pElement->QueryInterface(IID_IHTMLElement2, (void**)&pElement2);

        if (FAILED(hr))
            return true;

but i get an ASSERT error in atlcomcli.h line 149 Expression: p==0
following the stack, it is from the line indicated in the above code where I try to reuse pElement again
should i create another IHTMLElement?

 

by: DrivenXPosted on 2008-02-01 at 13:51:34ID: 20801100

I was looking through the CreateImage function and commenting parts of the code out until I found the code which contributed to the high mem usage i see from task manager.  (something which i should have done in the beginning..) and it turns out to be the following:

        CRect rect(CPoint(0, 0), srcSize);
 
        //      The WebBrowswer window size must be set to our srcSize
        //      else it won't render everything
        MoveWindow(&rect);
        m_pBrowserWnd.MoveWindow(&rect);
 
        COleVariant       vUrl(szSrcFilename, VT_BSTR),
                                  vFlags(long(navNoHistory | navNoReadFromCache | navNoWriteToCache), VT_I4),
                                  vNull(LPCTSTR(NULL), VT_BSTR);
        COleSafeArray vPostData;
 
        if (m_pBrowser->Navigate2(&vUrl, &vFlags, &vNull, &vPostData, &vNull) == S_OK)
                //      We have to pump messages to ensure the event handler (DocumentComplete)
                //      is called.
                RunModalLoop();
        else
                return FALSE;


where CComPtr<IWebBrowser2> m_pBrowser
RunModalLoop() is the line that causes the ~70,000K increase in mem usage
what exactly happens inside this function? Is there anyway to free the resources it used after the loop ends?

 

by: DrivenXPosted on 2008-02-04 at 16:31:52ID: 20819635

The memory leak was coming from two dlls, provided by mcafee (mytilus.dll) and itunes bonjour service (mdnsnps.dll).  After unregistering these 2 dlls and some tweaking of the code with suggestions from jkr and evilrix, i think the mem usage is acceptable.  Thanks

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...