Public Group

Memory Leak?

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

Recommended Posts

When I run my SDL program (I didn't post this in SDL because that information isn't really relevant), and I look in the Windows Task Manager, The amount of Pagefile usage goes up as long as it's running. When I close it, it goes back to normal. Does this mean anything? Also, i'm using Code::Blocks. Is there anyway to check for a memory leak using the debugger?

Share on other sites
Quote:
 Original post by UphoreumWhen I close it, it goes back to normal. Does this mean anything?

Sounds indeed like a memory leak.

Quote:
 Is there anyway to check for a memory leak using the debugger?

Alas no. You need to either use a leak checker (I am not aware of free ones that run under Windows, sorry), or hack up operator new and operator delete to report leaked memory at program exit.

Share on other sites
Hmm... I just noticed that it's been happening on other games I've made. When it reaches about 900MB, it freezes up and I can hardly move the mouse. It goes right back down when I close the program though.

Here is the source code to a game that has this problem

Sorry to give a big chunk of code, but I don't know what else to do. I'll do some testing however.

Share on other sites
Have you tried using the standard <deque> header rather than <deque.h>?

Share on other sites
Well, I don't think that has anything to do with it, because the other programs don't use it. But I think I found where the problem is happening. It seems to happen when I'm drawing graphics. I took all the graphic drawing funtions out of a problem program and pagefile usage was steady. I just don't see what I'm doing wrong?

Share on other sites
Also, when I was running this program, I didn't go past the main menu function, which means the problem happens in there too, so the code is now narrowed down to:
void MainMenu(){     while(run)     {     ClrScreen();     SDL_Color WHITE = {255,255,255};     txt = TTF_RenderText_Solid(menuFont, "Old Skool Cobra",WHITE);     DrawSprite(txt,buffer,40,30);     txt = TTF_RenderText_Solid(menuFont, "Press Any Key", WHITE);     DrawSprite(txt,buffer,45,120);     txt = TTF_RenderText_Solid(menuFont, "To Continue.", WHITE);     DrawSprite(txt,buffer,55,180);     SDL_Flip(buffer);          SDL_Event event;                    //Test For Events     		while(SDL_PollEvent(&event)) {			switch( event.type ) {                    case SDL_QUIT:					run = false;					break;				case SDL_KEYDOWN:                     Game();                     break;                     }                     }} return;     }[/SOURCE

Share on other sites
also:
void DrawSprite(SDL_Surface *surface, SDL_Surface *targetSurface, int x, int y) {     if(SDL_MUSTLOCK(targetSurface))     {        SDL_LockSurface(targetSurface);     }                                      //Create Rectangle For Coordinates	SDL_Rect destination;    //Give Rectangle Coordinates	destination.x = x;	destination.y = y;    //Blit Image to Buffer	SDL_BlitSurface( surface, NULL, targetSurface, &destination );		if(SDL_MUSTLOCK(targetSurface))    {       SDL_UnlockSurface(targetSurface);    }}

Share on other sites
Odds are that TTF_RenderText_Solid allocates a new graphics entity every time you call it. That would indeed be a leak. Take the calls out of the loop, use a separate pointer for each chunk of text you need to render, and look for the appropriate deallocation routine in the library.

Share on other sites
Don't you need to call SDL_FreeSurface() for each TTF_RenderText_Solid() call?

Share on other sites
Checking the documentation confirms that it indeed is the case:

Quote:
 Returns: a pointer to a new SDL_Surface. NULL is returned on errors

Use SDL_FreeSurface to release the surface once you no longer need it.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 31
• 16
• 11
• 10
• Forum Statistics

• Total Topics
634118
• Total Posts
3015610
×