Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

SO, I read a bit on Garbage Collection lately, out of curiosity, and there is something that is repeated quite often: garbage collection can lead to sudden slow down of the program, depending of the "depth" of the collection.

But in video games, there is a moment where the user can't really notice a small lag: loading screen. So, I thought, it might be useful to proceed to full garbage collection during a loading phase (via Collect()), having to wait a second or two longer should not really impact the user.

My question is, is it really useful, or are there no real benefit to doing this?

share|improve this question
up vote 12 down vote accepted

Yes, call it as the last thing you do when loading.

This will maximize the time between the level starting and the first lag due to a GC.

You should also be trying to minimise allocations in general too though so you don't get any more lags during a level.

See Poor performance on 360 and WP7 and Twin Paths To Garbage Collector Nirvana

share|improve this answer
Also it's pretty-much the ONLY time you should call it - especially on the compact frameworks (XBox, WinPhone). – Jonathan Dickinson Mar 15 '12 at 11:48
@JonathanDickinson: Absolutely. It should only really be called where the user would expect a pause (loading typically, maybe saving too), and definitely not as part of a loop / regular event. – George Duckett Mar 15 '12 at 11:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.