Jump to content
  • Advertisement
Sign in to follow this  
Uphoreum

Memory Leak?

This topic is 4448 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

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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Uphoreum
When 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

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!