How to setup MFC memory leak detection

Hi,

All of my past projects have been begun as generic MFC applications,
and I'm used to getting object dump messages when I close an app that
has memory leaks. Right now, however, I'm working on an app that did
not start out as an MFC app (it's actually a visual studio project
generated by the Qt code generator, though I don't think that matters
here); rather, it's a general C++ project. My question is: how do I
setup whatever is needed so that I can get back those nice object dump
messages. I've already altered the project settings to include MFC.
What else do I need to do?

Thanks,
Seward
0
10/26/2004 8:25:50 PM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
520 Views

Similar Articles

[PageSpeed] 18

>All of my past projects have been begun as generic MFC applications,
>and I'm used to getting object dump messages when I close an app that
>has memory leaks. Right now, however, I'm working on an app that did
>not start out as an MFC app (it's actually a visual studio project
>generated by the Qt code generator, though I don't think that matters
>here); rather, it's a general C++ project. My question is: how do I
>setup whatever is needed so that I can get back those nice object dump
>messages.

Seward,

Call _CrtSetDbgFlag at the start of your program. See the article
titled "Detecting and Isolating Memory Leaks Using Microsoft Visual
C++" on MSDN for more information.

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
10/26/2004 9:04:30 PM
Take a look at this:

http://www.flipcode.com/articles/article_memoryleaks.shtml

It's a nice simple way of looking for, and finding memory leaks!

One thing I should warn you about, there are occasions when Visual C++ will 
report Memory Leaks that arn't exactly real. This is usually things that are 
declared in a global variable that can be released after VC thinks 
everything should have already been released.

Good Luck!

M

"David Lowndes" <davidl@example.invalid> wrote in message 
news:rsetn0tnhg8m3g3m9so0ql1evl21l5vfdb@4ax.com...
> >All of my past projects have been begun as generic MFC applications,
>>and I'm used to getting object dump messages when I close an app that
>>has memory leaks. Right now, however, I'm working on an app that did
>>not start out as an MFC app (it's actually a visual studio project
>>generated by the Qt code generator, though I don't think that matters
>>here); rather, it's a general C++ project. My question is: how do I
>>setup whatever is needed so that I can get back those nice object dump
>>messages.
>
> Seward,
>
> Call _CrtSetDbgFlag at the start of your program. See the article
> titled "Detecting and Isolating Memory Leaks Using Microsoft Visual
> C++" on MSDN for more information.
>
> Dave
> -- 
> MVP VC++ FAQ: http://www.mvps.org/vcfaq 


0
10/26/2004 9:27:58 PM
Or one can always purchase a 3rd pary plugin that extends error checking. 
For example I think BoundsChecker will catch leaks.  It does cost money. 
But as is often the case it may be cheaper to pay for something like that 
than it is to research homegrown solutions.

"M" <ihatespam.0.a101888@spamgourmet.com> wrote in message 
news:yjzfd.160356$BI5.158930@fe2.news.blueyonder.co.uk...
> Take a look at this:
>
> http://www.flipcode.com/articles/article_memoryleaks.shtml
>
> It's a nice simple way of looking for, and finding memory leaks!
>
> One thing I should warn you about, there are occasions when Visual C++ 
> will report Memory Leaks that arn't exactly real. This is usually things 
> that are declared in a global variable that can be released after VC 
> thinks everything should have already been released.
>
> Good Luck!
>
> M
>
> "David Lowndes" <davidl@example.invalid> wrote in message 
> news:rsetn0tnhg8m3g3m9so0ql1evl21l5vfdb@4ax.com...
>> >All of my past projects have been begun as generic MFC applications,
>>>and I'm used to getting object dump messages when I close an app that
>>>has memory leaks. Right now, however, I'm working on an app that did
>>>not start out as an MFC app (it's actually a visual studio project
>>>generated by the Qt code generator, though I don't think that matters
>>>here); rather, it's a general C++ project. My question is: how do I
>>>setup whatever is needed so that I can get back those nice object dump
>>>messages.
>>
>> Seward,
>>
>> Call _CrtSetDbgFlag at the start of your program. See the article
>> titled "Detecting and Isolating Memory Leaks Using Microsoft Visual
>> C++" on MSDN for more information.
>>
>> Dave
>> -- 
>> MVP VC++ FAQ: http://www.mvps.org/vcfaq
>
> 


0
river.ross (102)
10/26/2004 9:53:50 PM
"M" <ihatespam.0.a101888@spamgourmet.com> wrote in message
news:yjzfd.160356$BI5.158930@fe2.news.blueyonder.co.uk...
>
> One thing I should warn you about, there are occasions when Visual C++
will
> report Memory Leaks that arn't exactly real. This is usually things that
are
> declared in a global variable that can be released after VC thinks
> everything should have already been released.

.... which in my case amounts to many thousands of spurious not-leaks and
makes the feature completely useless, as nobody is ever going to carefully
diagnose each of these to see if it is real.

I've read many explanations of how to stop these spurious leak reports but
none of the mechanisms work for me ...

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk


0
tw2 (223)
10/27/2004 9:04:37 AM
Tim Ward wrote:
> I've read many explanations of how to stop these spurious leak reports but
> none of the mechanisms work for me ...

I do it by setting the dll that's causing spurious leaks to be delay loaded.

0
mac1 (347)
10/27/2004 12:09:03 PM
Groovy. Thanks, guys.
0
10/27/2004 1:11:12 PM
"Mihajlo Cvetanovic" <mac@RnEeMtOsVeEt.co.yu> wrote in message
news:417F8FDF.9020401@RnEeMtOsVeEt.co.yu...
> Tim Ward wrote:
> > I've read many explanations of how to stop these spurious leak reports
but
> > none of the mechanisms work for me ...
>
> I do it by setting the dll that's causing spurious leaks to be delay
loaded.

That looks like it'll need some research to find out whether it's going to
work ... in particular there's a statement that you can't rely on a delay
loaded DLL to get loaded automatically before you want to start accessing
data in it, and of course it is the data in these DLLs that is what's
causing the problem in the first place ... still, I've got most of the
source code for most of the DLLs, so I do have some chance of working out
whether this is possible.

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk


0
tw2 (223)
10/27/2004 1:13:49 PM
"Mihajlo Cvetanovic" <mac@RnEeMtOsVeEt.co.yu> wrote in message
news:417F8FDF.9020401@RnEeMtOsVeEt.co.yu...
> Tim Ward wrote:
> > I've read many explanations of how to stop these spurious leak reports
but
> > none of the mechanisms work for me ...
>
> I do it by setting the dll that's causing spurious leaks to be delay
loaded.

Indeed this idea turns out not to be useful for me either, as I just get
error LNK1194.

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk


0
tw2 (223)
10/27/2004 2:46:25 PM
Tim Ward wrote:
> "Mihajlo Cvetanovic" <mac@RnEeMtOsVeEt.co.yu> wrote in message
> news:417F8FDF.9020401@RnEeMtOsVeEt.co.yu...
> 
>>Tim Ward wrote:
>>
>>>I've read many explanations of how to stop these spurious leak reports
>>> but
>>>none of the mechanisms work for me ...
>>
>>I do it by setting the dll that's causing spurious leaks to be delay
>> loaded.
> 
> Indeed this idea turns out not to be useful for me either, as I just get
> error LNK1194.

Tough luck. Maybe you could use _CLIENT_BLOCK instead of _NORMAL_BLOCK 
and instruct MFC somehow to ignore client blocks when searching for leaks?

Of course you could always use _CRT_BLOCK, but, like with 
TerminateThread, this should be the last resort.

The most elegant solution would be to remove all static allocations 
altogether, but that usually takes considerable time to do.

0
mac1 (347)
10/28/2004 9:34:51 AM
"Mihajlo Cvetanovic" <mac@RnEeMtOsVeEt.co.yu> wrote in message
news:4180BD3B.5030708@RnEeMtOsVeEt.co.yu...
>
> The most elegant solution would be to remove all static allocations
> altogether, but that usually takes considerable time to do.

Wouldn't be allowed. The main user of these DLLs uses a Linux build, and I
won't be able to change them that seriously just to suit the debug version
of the Windows build for a peripheral product.

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk


0
tw2 (223)
10/28/2004 11:17:48 AM
Tim Ward wrote:
> "Mihajlo Cvetanovic" <mac@RnEeMtOsVeEt.co.yu> wrote in message
> news:4180BD3B.5030708@RnEeMtOsVeEt.co.yu...
> 
>>The most elegant solution would be to remove all static allocations
>>altogether, but that usually takes considerable time to do.
> 
> 
> Wouldn't be allowed. The main user of these DLLs uses a Linux build, and I
> won't be able to change them that seriously just to suit the debug version
> of the Windows build for a peripheral product.

Ok, my last try: in dll for every global object instead of

SomeClass someValue;

use

#define someValue someValueHELPER()

SomeClass& someValueHELPER(void)
{
   static SomeClass someValue;
   return someValue;
}

The rest of the code shouldn't be changed. In this case there shouldn't 
be LNK1194 error. The HELPER function can also be #defined.

0
mac1 (347)
10/28/2004 5:55:00 PM
Reply:

Similar Artilces:

Page Setup
Hi, I have a problem with Excel XP in that when I preview a page which is in Landscape, it automatically displays as portrait. When I resize it, it goes back to landscape but then back to portarit again ! Any ideas ? Many thanks. Colin. If you change printer drivers, does it happen? If no, then I'd download a newer/fresh printer driver for that troublesome printer. Any chance you have some helpful macro jumping in to fix the page setup for you? If you open the workbook with macros disabled, does it still happen? Colin wrote: > > Hi, > > I have a problem with Excel X...

The best Exchange setup in a small hosting setup
I need to set up at small hosting setup where the users can access their email through RPC-HTTPS and webmail. But what do I need? One ISA server? One front-end server? One back-end server? Some clustering or is it overkill? Best Regards Martin - You can do it with as little as a single Exchange server and a firewall. - In a single server environment, FE/BE topology doesn't really buy you much... - Clustering can be an overkill or not, depending on what your goals are. If high-availability is a valued goal, you could look at clustering (and the investments that go with a clustered ...

ftps mfc c++
Does anyone know how to implement FTPS(FTP over SSL) client with mfc classes. I'm wondering whether the MFC supports FTP over SSL. If you know how, could you please post some sample code. Thanks ...

MFC Database programming #2
Hi! I have an MFC project, which use an MS-ACCESS db. is there any control, which brings capability the same as DataGrid of a Windows Form, to Dialog forms of MFC? ...

Problem with MFC code with ActiveX
Hi, I created one dialog based application. When i draw listbox on dialog box and then any activeX partially overlapping the listbox. As at build time AcitiveX control is behind the Listbox control. But after running, AcitiveX comes to the front. I need to have ActiveX behind the listbox at runtime also. Or AcitveX contorl' position should be consistence in both run and build mode. I am putting this problem again, I need to solve it very urgently, Please suggest some ideas. -Narayan Narayan, This sounds like the old, well known "z-order-in-the-resource-editor-bug", ...

excel page setup
Hello, I have a spreadsheet and I am using cells a:k50, but when I go to see the end of my spreadsheet it tells me I have used cells a:ak 295. I have 35 sheets like this and is is making the file bigger than it has to be. I have tried deleting, clear, page preview setup but nothing seems to clear and make my page a1: k53. Any suggestions. Thank You Select the row following the end of your data. Ctrl+Shift+Down Arrow to select all rows beyond your data and Edit>Delete. Select the column following the end of your data. Ctrl+Shift+Right Arrow (US) to select all columns beyond your data...

Automating Headers in Word from VC++/MFC
Any one able to help in the correct sequence of events in creating a header from VC++ using MFC ?? I mean like giving me a complete example of code how to make say 2 sections in a .doc, Each section with it's own Header...Say each section has a table in it...I would like specific examples of how to use the Selection, Section,Tables, Table objects to do this if possible....I'm looking for the secquence of events again...Creating each object and in what sequence, how to make SectionBreaks if necessary in a table that may take more than one page, and get a different header on first page o...

MFC-app starting WINDOWS Screensaver window z-order problem
Hi! I wrote an MFC-app using VC++.NET 2003, which starts a screensaver using CreateProcess(). It also terminates the screensaver using TerminateProcess() / CloseHandle(). If the user activates mouse/keyboard before my app terminates the screensaver-process, the screensaver terminates itself and the z-order and focus-handling of open windows somehow gets mixed up. this just happens when I use CreateProcess(), when I use PostMessage(WM_SYSCOMMAND, SC_SCREENSAVE, 0) for the standrad-screen-saver, everything works fine, but I dont want to use this approach. maybe the system uses different CreateP...

Account setup is temporarily unavailable. Please try again later.
I just upgraded to money '05 because my bank no longer allows acess using money '02. I have been getting this message for TWO WEEKS now. I set up three accounts with no problem, then this message over and over every day. I have tried starting a new account and I still get the same message. Surely MS's server has not been down this whole time, so I guess the problem is on my end. Please Help! In microsoft.public.money, lostmymirth wrote: >I just upgraded to money '05 because my bank no longer allows acess using >money '02. I have been getting this message for T...

[ANN] The Entourage Help Blog: "Updated Exchange setup script supports Entourage 2008"
I've posted version 2.0 of my EntourageExchangeSetup AppleScript on The Entourage Help Page that includes support for Microsoft Entourage 2008's Kerberos feature as well as some minor additions and bug fixes. This AppleScript is intended to be modified by an administrator to assist his Entourage users with the setups of their Exchange server accounts. It has been tested specifically with Entourage 2004 11.2.6, 11.3.3, 11.3.7 and Entourage 12.00, 12.0.1 and 12.1.0 but should work with any version of Entourage 2004 SP2 (11.2.0) and higher. Every company's network is different...

SETUP
HOW DO I SET IT UP. Windows Mail: Setting up an account from start to finish http://windows.microsoft.com/en-US/windows-vista/Windows-Mail-setting-up-an-account-from-start-to-finish -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "home" <phillipsjamest@att.net> wrote in message news:u1ikLZSALHA.980@TK2MSFTNGP04.phx.gbl... > HOW DO I SET IT UP. "home" <phillipsjamest@att.net> wrote in message news:u1ikLZSALHA.980@TK2MSFTNGP04.phx.gbl... > HOW DO I SET IT UP. Start here and look for mail settings. ht...

Anonymous Access setup
I have a request to turn on anonymous access (MOSS 2007). We only have one Site collection and it’s an Intranet that uses Authentication Type; Windows and Integrated Windows Authentication. It seems straight forward first Enable IIS Anonymous Authentication, second Enable anonymous access for the Web Application needed, turn on anonymous access for list or site. Question: If I turn on anonymous access without enabling it on any sites or lists will my users notice anything different? I assume they will not notice anything. Next question; if I enable anonymous authentication on...

Profile Setup
When I enter the server name and mailbox name when setting up an Outlook 2003 profile, how does it lookup the name? It seems I can put any name in the server area as long as I have a valid mailbox name. I used a made up server name and it still resolved the mailbox. Thanks, Outlook 2003 uses the Global Catalog servers in an AD environment. (Exchange 200x refers Outlook 2000/2003 to the GCs.) Outside of that, I didn't think what you just did was possible since a new profile (o/s and outlook) shouldn't have a reference to a GC until checking in with Exchange. Guess Outlook ...

Payroll Posting Account Setup Window
We have customized the Payroll Posting Account Setup Window for a product of ours. We have received several complaints about the Payroll Posting account window changing the Account number if part of a record in the scrolling window has been modified. We turned off the customization so we were working with the core window and not the customized window and we were able to duplicate the error. The new account is being saved in the table, which is causing a tremendous problems. Here are the steps to recreate this issue. 1. modifiy any record -for instance the code field of any record an...

Report setup 01-12-08
I have a db that the client wants me to prepare a report of transactions, from the transaction table, in the following format: (TT = transaction types) (Each lot may have none or many transactions of each type) TT1 TT2 TT3 TT4 lota 0 10 8 2 lotb 5 0 0 1 lotc 1 5 0 0 "" etc. I am able to create a report that has the lots listed sequentially, then the details of the lot transactions, but not in the above format. Any ideas? Damon Create a new report using the wizard. When it asks you for grouping options, se...

Multiple mfc activex controls in one dll
In VS6, there was a possibility to define up to 4 controls, when creating a new activex project. No such possibility in VS2005. Is there any way in 2005 to add an addtional one to an existing MFC ActiveX project? Any pointers will be appreciated! ...

Access a regular dll using shared MFC Dll from a console application
Hi I was wondering if anyone can point me to any sample code for a console application using a regular dll using shared MFC Dll. I want to be able to use Dialogs from the MFC library for my console application. I appreciate it. Danny ...

setup.exe /removeorg
Hi, I uninstalled exchange 2003 using the add/remove programs. Then a reboot and a few hours to replicate. Then ran setup.exe /removeorg. I noticed that there was still objects leftover from exchange 2003 in AD, such as: Exchange Groups,Exchange settings in sites and services, distribution groups and disabled users. What exactly does the removeorg remove other that exchange 2003 organization? How do I clean the rest of the mess up? thx jason Hi Jason, You may want to view the following KB: 830185 The REMOVEORG option in Exchange Server 2003 http://support.microsoft.com/?id=830185 ...

Page Setup
Is it possible to have portrait and landscape pages within the same Visio file? Every time I change the layout for one page it changes them all. I am runing Visio 2000 under NT4. Thanks, Andy Yes. IIR UML diagrams don't like doing this but otherwise it's easy. When you insert a new page the Page Setup dialog will come up. Select the Page Size tab, custom size option button, then select page orientation. "Andy Saltiel" <Andy.Saltiel@atosorigin.com> wrote in message news:09b301c35ceb$7c95d510$a601280a@phx.gbl... > Is it possible to have portrait and landscape...

Detect if vertical scrollbars visible in listbox ?
I have a need to know if there is data that can be scrolled to in a listbox. I'd rather not check the number of items listed since the height of the listbox may change. Is there a way to detect if the vertical scrollbars are visible or not? Thanks. "mscertified" <rupert@tigerlily.com> wrote in message news:42E5F377-C696-4FFF-9404-0D7E69D469D4@microsoft.com... >I have a need to know if there is data that can be scrolled to in a >listbox. > I'd rather not check the number of items listed since the height of the > listbox may change. > Is there a way...

Detect & Repair Question Please
I am running XPPro & Office 2000 Small Business edition. Every so often Outlook refuses to start & I must run "detect & repair" and that fixes it okay (I still don't know what's causing this however). My question is: when I chose "detect & repair" I an asked to put in my original installation disc. This is a pain. Surely whatever detect & repair is looking for can be installed on my hard drive so I don't have to keep going back to the install disc. Help please. Thanks in advance... Bob ...

Rules and Alerts gives me Out of memory or system resources error
Outlook 2003 Every time I go to "Tools" / "Rules and Alerts" I get the following error: Microsoft Office Outlook: Out of memory or system resources. Close some windows or programs and try again. Everything else is working perfectly fine, it's just this one function. thanks I am getting the same error from any PC that has Outlook 2003 installed! This is really annoying. Anyone with similar problem? gougler wrote: > Outlook 2003 > Every time I go to "Tools" / "Rules and Alerts" I get the following > error: > > Microsoft Office Out...

strange memory leak problem
Hi all, I use _CrtSetBreakAlloc to break the code at the point the leaking memory is allocated and find that it is a CString allocated locally within a function. void Myclass::PrintInfo(CString &strTmp) { ....... CString strUser( "bah"); strTmp.Format(IDS_START_INFO, strUser,); ...... } Additionally I have found some other memory leaks occur in STL stream API calls, like << >>. This string will be freed when the variable leaves scope. What is the evidence that this is leaking memory (if you're relying on CrtMemCheckPoint, know that it doesn't work. ...

Question on Printer Setup
I have two printers, one POS receipt printer and one laser printer. What i would like to do is is just use the laser printer because it has the 8 1/2 X 11 paper and i can put more info like company policy, items and with descriptions etc. My problem is i need a way to open the drawer and the only way would be is print out with the pos receipt printer. Is there a way to print out with both at the same time so the receipt printer will open the drawer and the laser would be for the invoice? Or does anybody have a solution for this? This is a multi-part message in MIME format. ------=_N...

mfc error
Microsoft is reporting an mfc error and I want to know how to delete the problem ...