What is Leaking?

Started by
10 comments, last by demonkoryu 18 years, 7 months ago
While I was testing my map editor,I noticed that my program eats more and more memory after loading new maps.For example if no map is loaded,editor eats around 15mb,when I load a map it goes up 25mb,then with loading same map(of course deleting the old map from memory) it goes up 32mb!Then with a new load it goes up to 40mb.This is really ridicioulus ,editor should comsume same amount of memory,because I load exactly the same map after deleting it!I thought there might be memory leaks.I downloaded a bunch of software to see the leaks;Yes,there were some memory leaks.I fixed them all.But still this problem occurs.I don't understand,the memory leak detection programs show me that no memory leaks detected,but why is this problem still occurs?What do you suggest me to do?Did you have problems similar to this and how did you solve it?Please help.
Advertisement
you could overload the new and delete operators and keep track of memory allocation easily.
You were using Task Manager, weren't you... As has many times been said before this, and will doubtless be said many times after, do not use task manager to look for memory leaks! It is not accurate in that facility, get a proper leak detector, or write your own with overloaded new and deletes. I'd say that if your current leak detector says no leaks, then there are no leaks.
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!
Memory Managers give you a report on the memory allocate with new and deleted with delete, but maybe not with malloc() and free(). Also if you use external libraries, their allocations might not show up.

EDIT : Oh yeah, Task Manager is dumb. Don't trust it.

Everything is better with Metal.

Thanks guys.Yeah,I use Task Manager.What should I use for seeing the memory usage?What do you suggest?

Look up memory leak detection on MSDN, or similar.

Failing that and you can afford it look up boundschecker.
you could use "perfmon" comes with windows, also MSDN have a nice treatment on leak detection if you want something a bit more hardcore.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Have a look at valgrind it's an excelent memory debugger that helps you
to find memory leaks (and much more).

Have a look at the implementation of smart pointers with reference counting
if you can't handle the problems manually.
Here is one handy way to catch the memory leaks , I am using right now

#include <stdio.h>#include <stdlib.h>//used for debugging memory leaks#include <crtdbg.h>int main(){     char *leak = (char*)malloc(64);     leak = (char*)malloc(64);     free(leak);    _CrtDumpMemoryLeaks();    return 0;}
You could try Paul Nettle's mmgr.

This topic is closed to new replies.

Advertisement