Jump to content
  • Advertisement
Sign in to follow this  
Ekim_Gram

SDL Game slowing down after some time of play

This topic is 4812 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 currently completing my Tetris clone and I've come to notice after a while of playing it, my computer begins to slow down. And on older computers, after a while an error will come up saying it ran out of virtual memory. I'm assuming this would maybe be a memory leak with the surfaces? I've got a 10x19 array of SDL_Surface*'s and a number of SDL_Surface*'s that I use with game text and such. When changing game states like going from the menu to playing the game, or from playing the game to the high score board, should I be freeing the surfaces and load them again whenever I need them or is that a totally wrong way to go?

Share this post


Link to post
Share on other sites
Advertisement

Quote:

And on older computers, after a while an error will come up saying it ran out of virtual memory. I'm assuming this would maybe be a memory leak with the surfaces?


Not necessarily the surfaces, might be normal new int[200] you put somwhere in main loop, and forgot to delete [] when it's not needed. That way, you would be allocating 200 * 4 bytes each frame, what eventually means - running out of RAM, and running out of virtual memory.

Try sth like this: search for new in all your project files - count them. Then, search for all delete instructions - if numbers aren't equal, you've got obvious memory leak :-)


Quote:

When changing game states like going from the menu to playing the game, or from playing the game to the high score board, should I be freeing the surfaces and load them again whenever I need them or is that a totally wrong way to go?


If it's already loaded into memory - why on Earth would you want to release it and load again?

Share this post


Link to post
Share on other sites
Quote:
Original post by Koshmaar

Not necessarily the surfaces, might be normal new int[200] you put somwhere in main loop, and forgot to delete [] when it's not needed. That way, you would be allocating 200 * 4 bytes each frame, what eventually means - running out of RAM, and running out of virtual memory.

Try sth like this: search for new in all your project files - count them. Then, search for all delete instructions - if numbers aren't equal, you've got obvious memory leak :-)


I don't have any of those in there, the only new I have is new CEngine Engine and in my CleanUp() function which is called right before return 0 is delete Engine.

Share this post


Link to post
Share on other sites
Ok, so it looks that you're allocating sth with SDL (or other libs) each frame, without releasing it after.

Maybe you could try using memory manager (like this: Fluid studio mmgr) or posting more code?
Also, search for places where you're allocating SDL_Surfaces / sounds / other resources in your main loop.

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!