Does anyone know a good method of garbage collecting for my game. Im just starting out, and im really just collecting all of my information right now, so i know what im up against going into this thing, so if you could give me a few pointers, its appreciated.

God Bless

Re: XNA Game Studio Express Garbage Collecting


One of c#'s features is automatic garbage collection. Once all references to an object are all released, the object is flagged for garabage collection and will be deleted in a short while. Just make sure you aren't creating an obscene number of temporary objects and you should be fine. One more thing: avoid foreach loops on the xbox because it create needless garabge in every run. On windows, it's not as much of a problem because the garbage collector is more efficient in windows.

Re: XNA Game Studio Express Garbage Collecting

Ska Software

Don't use foreach and string.ToLower() !


That's my personal experience.

Re: XNA Game Studio Express Garbage Collecting

Dan Lingman

If possible, create a pool of your objects up front, and recycle them.

One way to do this is to keep two arrays of objects - one live, and one suspended.

When you need a new instance, walk the suspended array looking for a non-null value, and remove it, copying the reference to the live array. when you remove one from the live array, put it back in the first empty (null) spot in the suspended list.


Projectile[] liveMissiles = new Projectile[25];

Projectile[] suspendedMissiles = new Projectile[25];

int i;

for (i = 0; i < 25; i++) {

suspendedMissilesIdea = new Projectile();


// get new missile

Projectile getMissile(){

for (i = 0; i < 25; i++) {

if (suspendedMissilesIdea != null) {

Projectile missile = suspendedMissilesIdea;

suspendedMissilesIdea = null;


return missile;


return null; // we underestimated the number we need


void addLiveProjectile(Projectile missle){

for (i = 0; i < 25; i++) {

if (liveMissilesIdea == null) {

liveMissilesIdea = missile;