• Advertisement

Archived

This topic is now archived and is closed to further replies.

how to find memory leak

This topic is 5502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m making a model loader and using dynamic memory allocation(malloc & realloc) to allocate memory during importing the model. Then there''s a function to destroy the model using free() function. I did a test to monitor memory leak when I repeatedly import and destroy a model. I used norton systemwork to monitor the PHYSICAL memory used. Everytime I import the model the memory used will increase but when I destroy the model, the memory used will decrease less than it increased(differs by around hundred kilobytes)... so I guess there''s a memory leak in my program... Is this the correct way to monitor memory leak? How to make a program that can calculate how much memory leak it has ?

Share this post


Link to post
Share on other sites
Advertisement
Use a memory manager. I sent you an email with one memory manager ready to use. Just include "Memory_Manager.h" after the <> includes and that''s it.

Example:

#include <windows.h>
#include <stdio.h>

#include "Memory_Manager.h"

// The rest of your includes goes here.

Hasta

Share this post


Link to post
Share on other sites
Thanks... I''ve downloaded the files and beginning to study it...

Share this post


Link to post
Share on other sites
How do the memory managers work? Do they redefine the new/malloc function?

PM

Share this post


Link to post
Share on other sites
They redefine new, new[], delete, delte[], malloc, realloc, calloc and free.

Hasta

Share this post


Link to post
Share on other sites
Cool, would you mind posting those on the forums? I''m sure they would come in useful for everyone here .

Share this post


Link to post
Share on other sites
quote:
Original post by Mr_Mav
Use a memory manager. I sent you an email with one memory manager ready to use. Just include "Memory_Manager.h" after the <> includes and that''s it.




Do you know where can I find a memory manager on the web ?

Share this post


Link to post
Share on other sites
Paul Nettle (Midnight) wrote a good (free) memory manager...

Here''s some stuff from the readme file :

"This code originally appeared on www.flipcode.com as an entry to the "Ask Midnight" column titled "Presenting A Memory Manager":

http://www.flipcode.com/askmid/archives.shtml "

And

"You can find the latest version of this source at:

ftp://ftp.GraphicsPapers.com/pub/ProgrammingTools/MemoryManagers/

!IMPORTANT! Please spend just a couple minutes reading the comments at the top of the mmgr.cpp file... it will save you a lot of headaches!"

We scratch our eternal itch
A twentieth century bitch
We are grateful for
Our Iron Lung

Share this post


Link to post
Share on other sites
quote:
Original post by slyterence
...You can find the latest version of this source at:

ftp://ftp.GraphicsPapers.com/pub/ProgrammingTools/MemoryManagers





That link doesn''t work for me...

I googled it and found this one tho





"If you gaze long into an abyss, the abyss will gaze back into you."
- Friedrich Nietzsche (1844-1900)

(my site)

Share this post


Link to post
Share on other sites
msvc already comes with an excellent debug heap, why not use it?

Share this post


Link to post
Share on other sites
I''m trying to get this memory manager to work, but I can''t compile anything without getting these errors:

c:\program files\microsoft visual studio\vc98\include\stdlib.h(281) : warning C4002: too many actual parameters for macro ''calloc''
c:\program files\microsoft visual studio\vc98\include\stdlib.h(281) : error C2059: syntax error : ''string''
c:\program files\microsoft visual studio\vc98\include\stdlib.h(283) : error C2062: type ''void'' unexpected
c:\program files\microsoft visual studio\vc98\include\stdlib.h(298) : error C2059: syntax error : ''string''
c:\program files\microsoft visual studio\vc98\include\stdlib.h(306) : error C2059: syntax error : ''string''

Any ideas?

Share this post


Link to post
Share on other sites
It probably replaces malloc, free and the other function using a define, so make sure to include it after you include stdlib.h.

Share this post


Link to post
Share on other sites
Ok it works now

I just didn''t realize that I had to include stdlib.h as well...

Share this post


Link to post
Share on other sites
Thanks for the link slyterence... I finally figured out why my program is crashing

The manager is telling me that "A memory allocation unit was corrupt because of an overrun" and gives me a line number and everything

Problem is I don''t know what this means, and after looking over the code it seems to be fine...

Share this post


Link to post
Share on other sites
it likly means that you wrote into memory outside of the allocated memory block.

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |

Share this post


Link to post
Share on other sites

  • Advertisement