Sign in to follow this  
starstriker1

Tracking down memory leaks

Recommended Posts

starstriker1    245
I've run into a bit of a snag with my game. Somewhere, resources aren't being freed when I close the game and after running my program many times, I find that the free memory my computer has is gone, and I get a strange delayed input effect when I run my game, where pressing a button doesn't get an effect until about half a second later. Knowing that the memory leaks are there is one thing, but tracking them down is troublesome. Are there any programs or features of MSVC++ that I can use to make sure that I free memory that I allocate?

Share this post


Link to post
Share on other sites
S1CA    1418
Programs: BoundsChecker is the main one, but it's a commercial package so you'll have to purchase it (unless they still offer a time limited trial version).

Programming: Run your application in a debugger and use a memory manager which will help you detect and trace memory leaks. As luck would have it, the MSVC C runtime library has built in support for this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/_core_Solving_Buffer_Overwrites_and_Memory_Leaks.asp?frame=true

Share this post


Link to post
Share on other sites
pants    147
Creating a memory manager for your source base is a good idea, here is a tutorial on the steps needed to create one. There are also several libs floating around the internet that are usually very easy to plug into most programs.

http://www.flipcode.com/articles/article_memoryleaks.shtml

Share this post


Link to post
Share on other sites
iMalc    2466
Quote:
Original post by starstriker1
I've run into a bit of a snag with my game. Somewhere, resources aren't being freed when I close the game and after running my program many times, I find that the free memory my computer has is gone, and I get a strange delayed input effect when I run my game, where pressing a button doesn't get an effect until about half a second later.

Knowing that the memory leaks are there is one thing, but tracking them down is troublesome. Are there any programs or features of MSVC++ that I can use to make sure that I free memory that I allocate?
Memory allocated within a process's heap is automatically freed (under Windows) when the process exits.

Are you running on Windows?
If you are, and you are closing your program each time, then you must be using up some kind of system resource, and new/delete trackers such as Paul Nettle's memory manager may not be able to help you much.

btw it might also pay to check the task manager and verify that the previous instances of the program have all quit when you think they have.

Share this post


Link to post
Share on other sites
Rhalin    246
Quote:
Original post by pants
Creating a memory manager for your source base is a good idea, here is a tutorial on the steps needed to create one. There are also several libs floating around the internet that are usually very easy to plug into most programs.

http://www.flipcode.com/articles/article_memoryleaks.shtml


I -very- highly recommend this artical. I've used it in one incarnation or another for many projects and found it the only overloading new/delete to work consistantly. A word of warning, it _will_ slow down your app quite a bit if you have a lot of dynamic allocation, so having a way to easily remove it is handy, and I definately wouldn't leave it in on a release build.

Share this post


Link to post
Share on other sites
Simplicity    158
[/quote]
Creating a memory manager for your source base is a good idea, here is a tutorial on the steps needed to create one. There are also several libs floating around the internet that are usually very easy to plug into most programs.

http://www.flipcode.com/articles/article_memoryleaks.shtml
[/quote]

The funny thing from the article is that the override new calls AddTrack which in turns calls new again. Seems like there will be recursion problem. I suggest replacing new with malloc.

[Edited by - Simplicity on October 23, 2005 9:59:19 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this