Garbage Collector, 2.6 versus 3.0

Hi,

I did the simplest test to check the difference from garbage collector from version 2.6 and 3.0, and I was surprised to see that the 3.0 garbage collector performs worse!

The test was really simple, creating 1000 objects each Update.

Im a little dissapointed, since currently I´m having problems with the garbage collector, and I was willing to solve with the 3.0 version. I could easily accept an equal performance, but many times less performance will certainly prejudice my upgrade efforts.

Is this test too simple? could you post a more acurate test to support 3.0 is better? (it should be… more recent mono, etc)
Anyone having problems with the garbage collector too? why the heck the gui elements spends so much memory???

[ ]s, gandhi


public class MemoryTest : MonoBehaviour
{
void Update()
{
int numberOfObjects = 1000;
for (int t = 0; t < numberOfObjects; t++)
{
new SomeStupidObject();
}
}
}

public class SomeStupidObject
{
public int number = 35;
public long number2 = 123123;
}

Mono 2.8 will come with a new, better GC. It should come out soon. Right now mono has some really basic GC that’s not really too magnificent for game use. Not sure if Unity guys made any changes there themselves.

Anyway, I tried upgrading Unity 3 mono to a preview version of 2.8 and it works (with some minor annoyances), so I hope when 2.8 GC finally hits it will solve a lot of problems. (2.8 GC is currently only available in linux preview versions of mono 2.8, so I didn’t get to try that)

I’m hoping we don’t have to wait for Unity 4 to get another mono version bump. The new sgen GC is something I’ve been looking forward to since it was announced.

yes you will because mono 2.8 is again not compatible with previous versions (no idea why they didn’t call it mono 3 due to this break)

also, the GC is hardly responsible for users doing stupid things (might sound harsh brut creating megs of trash data isn’t viable for anything, see end of post)

The reason that you take such a much higher hit now is that U3 has a more agressive “dead resources” cleaning (previously if you forgot to destroy something it hang around forever, now if you forget it and remove all references it will be cleaned).

if you want to create and destroy many objects in a row, I think its fair to expect that you use at very least basic game patterns, which in this case means object pooling, in which case you won’t get any alloc and dealloc at all for the game objects and for that reason also no GC hit and no OS alloc / dealloc hits.