Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new and delete matched up, but mem usage grows?

Status
Not open for further replies.

Nanoboy

Programmer
Jun 9, 2003
2
US
First post, thanks in advance for the help.

I've got a program which I am almost certain has no new-delete memory leaks. I can run it in debug with no errors on completion. However, when I watch task manager in Win XP home, the mem usage continues to grow (usually by 32K chunks). What does mem usage in task manager count, stack and heap? Eventually, I have to shut it down, reboot and restart my program when the mem footprint becomes too large. I am newing alot in the code, but I match them all will deletes. Any ideas on a culprit or a tool I can use to track this down.

Again, thanks in advance.
 
There are several commercial products that help detect memory leaks. Some of them even detect Windows OS Resource leaks which could be the problem you are having.

Bounds Checker is one of them but there are several.


-pete
 
Check these functions :

_CrtCheckMemory(), _CrtDbgReport(), _CrtDumpMemoryLeaks() and other functions in the same 'family'.

They will only work if your project is build with debug-info.

/JOlesen

 
Is your code exception-safe?

Code:
{
    int* x = new int;
    //exception thrown
    delete x;
}

x never gets deleted.
 
If you do have exception unsafe code, a quik way to fix it is to go to and get the smart_ptr library. Replace all T* with a boost::shared_ptr<T>. See if that fixes the problem. If it does, you can go through and selectively replace shared_ptrs with weak_ptrs, scoped_ptrs, and auto_ptrs (part of std) as necessary.
 
Thanks all, I did have an unmatched new. It was a stupid mistake in which under certain conditions I could new a variable again before deleting the old. I was also under the mistaken understanding that since debug in MSCV++ reports memory leaks in MFC apps, it would do it always. I didn't realize this was only for MFC applications. Since this is a windows consule, I had to use the _CrtCheckMemory(), _CrtDbgReport(), _CrtDumpMemoryLeaks() Family of functions to get the same thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top