XNA SpriteBatch Stalling every Second | Accidental Scientist

XNA SpriteBatch Stalling every Second

Public Service Announcement:

If you’re doing simple 2D sprite stuff in XNA, and every second or so, the GC is hitching, it’s because of SpriteBatch. Every call to SpriteBatch creates a new object, which eventually needs to be GC’d. This will give you a stall every second or so, as the GC runs and tries to clean up.

Kind of sucks really. Ultimately, it means that if you want to get around this, you’re going to need to write your own Sprite rendering code that allocates everything up front, and doesn’t release anything until a level change, and recycles as much as possible. Not too hard – just build a quad, and write the appropriate code to render it. But it’s a lot more work than just slotting it in, unfortunately.

About Simon Cooke

Simon Cooke is a video game developer, ex-freelance journalist, screenwriter, film-maker and all-round good egg in Seattle, WA. The views posted on this blog are his and his alone, and have no relation to anything he's working on, his employer, or anything else and are not an official statement of any kind.
facebook comments