Jump to content
  • Advertisement
Sign in to follow this  

memory leaks

This topic is 4285 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 writing a program in VC++ and noticed that as the program went on it got slower and slower, so i checked the task manager and sure enough the memory usage of my program kept on getting bigger and bigger. how do i find the source of this problem? Thanks.

Share this post

Link to post
Share on other sites
Thanks, i tried to do what it said in the articles and it worked, in the output window it said that it detected a leak and it said were it was in the memory but it didn't say were it was in the code - even though i defined
what could the problem be?

Share this post

Link to post
Share on other sites
Memory leaks are usually because you don't use 'delete' on every 'new' operators, or malloc() and free() for older stuff. Just look into every part that does this.

Also, make sure you are freeing up the information before you try to allocate more.

for example:
int x, *pointer;
pointer=new int[10];
/* do things with pointer */
delete pointer;

this makes it abundantly obvious, but with a real program I'm sure it'd be much easier to miss. :P

Sorry if I missed a reason... it's been a while and I'm rather against thinking right now...

edit: If I remember, there's at least one other thing in managed code that dynamically allocates memory, gcnew, that has to be manually released, so keep that in mind... again, sorry if I'm missing things and not explaining: it's been a while, especially sense I've messed with managed code. :P

trying to change that but having trouble finding documentation on C++ and managed code... I've been able to figgure it out but it is time consuming...
(and you see... I never specifically learned compiler theory and things like exactly what the heap is... >.> I just know code and what I need to troubleshoot compiling...)

Share this post

Link to post
Share on other sites
I forget where I found this snippet, but putting:

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;

at the top of a .cpp file will make msvc spit out where the memory that leaked was allocated, if it was allocated from that .cpp file.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!