Archived

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

Moe

Memory leak that I can't find...

Recommended Posts

Moe    1256
For some stupid reason I have a 2304 byte memory leak in my latest project. I know this because when I run it in debug mode (MS VC++) it says that it failed to de-allocate 2 objects/variables. I have tried looking all over the place to see if I am missing something, but I can't seem to find it. I was wondering if you would be so kind as to try to find my memory leak. The source code (nicely zipped up) can be found at http://www20.brinkster.com/tyrannica/memoryleak.zip If that doesn't work, you can try looking at my site in my signature. The source is nicely commented and fairly neat. EDIT - I misspelled the link and Brinkster doesn't like me linking directly to files. >_< Moe's site Edited by - Moe on December 12, 2001 11:45:21 PM

Share this post


Link to post
Share on other sites
python_regious    929
It means that you are assigning DIERR_INPUTLOST to hr, NOT testing to see if they are both equal, hence that if statement will always be true, regardless of the value of hr. Replace the "=" with "==" instead, that should solve your problem.

Share this post


Link to post
Share on other sites
Moe    1256
Actually, that didn't seem to fix the memory leak. Any other ideas on what's causing it? I really can't figure it out. And it only happens in fullscreen mode.

Edited by - Moe on December 14, 2001 6:57:42 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster

If you''re using C++ memory allocation with MS Visual Studio,
you can include the following macros in a header file, and
change all of you memory allocation to use DEBUG_NEW.

#ifdef _DEBUG
#include <crtdbg.h>
#define DEBUG_NEW new(_CLIENT_BLOCK,__FILE__,__LINE__)
#else
#define DEBUG_NEW new
#endif

Now when you program exits, it will spit out the where the
leaked memory was allocated from.

Share this post


Link to post
Share on other sites
Moe    1256
There''s a bit of a problem with that last post, seeing as I haven''t used ''new'' or ''delete'' in that program. Its got to be some stupid DirectX thing thats not being de-referenced (or something like that). I just figured that this would be a good thing to get cleared up before I get much further in my program.

Moe''s site

Share this post


Link to post
Share on other sites
Oluseyi    2103
Since you haven''t done any local memory allocation, then I must ask whether you release all your interfaces (in the reverse order they were acquired! )?

MSVC has a pretty good debugger. Yeah, it has its limitations (before the MSVC-bashers come in here) but it gets the job done. You set a breakpoint using F9: this is a line where you want the program to stop execution so you can take a look at the values of variables. You also clear a breakpoint using F9. You can then single-step (perform a statement at a time, also called step over) using F10, step-into a statement (it takes you inside function calls for example, including overloaded operators; MSVC will even take you inside many CRT functions if you installed the source), step out of a function you have previously stepped into using Shift+F11, and run up to wherever you position the cursor using Ctrl+F10.

You start debugging by pressing F5 within the MSVC IDE rather than Ctrl+F5.

While you''re debugging, there are a couple of extra windows available to you. The two you''ll use most frequently for now will be the Variables and the Watch windows. In the Variables window, MSVC will display any variable involved in the current statement or whose value has just changed. The names will be on the left and the value (including some aggregates, so you can examine the members of structs, etc) on the right. Changed values show up red. In the Watch window, you can type the name of any variable and watch its value change over the course of a statement block. MSVC will only track variables that are defined within the current scope though, so keep that in mind.

Good look.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites