-
traping leaking memory
hi again. again on the subject of dynamic memory allocation for arrays of strings, or whatever, is there any c function or any other way in general that catches memory leaks or tell how much mem is used at any point (i asume that if i make a log file with the free mem at regular intervals it may be possible to identify memory leaks)?
in general, how can i see the mem my prog uses at any time?
moreover, is there any trick to imitate destructors in c?
i'm asking this after realising that i was forgeting to free the mem i got from malloc...
thanks
null
-
When you dynamically allocate memory, you always have to remember to deallocate it. That's one of the problems with C, if you forget then you have a memory leak and there's no way to check for it.
-
Registered User
Little tool
Hi,
well there is one little thing you could do... Write a little program that counts the number of 'malloc' and 'new' statements in your sourcefiles and of course the number of 'free' and 'delete' statements.
Of course there can still be memory leaks and the programm might be confused in loops ( advanced version you also check loops, but it's realy tricky I think ), but might be worth a try It's a nice practice task for newcomers, too. And it's something you can later really use ... maybe
Greetings
cody
-