Unity4 sgen GarbageCollector

Does Unity 4 using Mono 2.8.2 enable generational garbage collector (sgen) or it’s still using Boehm collector?

If Boehm, how I can activate sgen GC?

And will it work on iOS?

sorry my english

Unity uses Mono 2.6.

–Eric

Mono has implemented generational garbage collection since v. 2.1, but there are a couple of things to consider. If memory serves me, Unity has made some enhancements to the garbage collector to aid in better performance in Unity (but I could be wrong on this one). It may also depend on the target platform.

For example, Windows Phone 8 supports generational garbage collection natively but Windows Phone 7 did not (before Mango). Anything based on the compact framework also did not support generational garbage collection (this was one of the big drawbacks of XNA when targeting xbox 360). I’m not sure how it’s treated on different platforms but I’m guessing when targeting iOS and Android you’re probably looking at a single-pass garbage collector.

You could set up some tests for this by loading up the heap and forcing a collection to see what happens. Keep in mind that it’s not the amount of memory you have allocated on the heap but the number of allocations and the heap complexity that make a big difference.

Another way to test… I can dig up some code I have for you that takes into account which collection generation you’re on and it could be adapted to detect whether or not multiple generations of collections are taking place and you could use that to target the mobile devices to find out.