views:

153

answers:

3

Hi, are there any CLR implementations that have deterministic garbage collection?

Nondeterministic pauses in the MS CLR GC inhibit .Net from being a suitable environment for real-time development.

Metronome GC and BEA JRockit in Java are two deterministic GC implementations that I'm aware of.

But have there any .Net equivalents?

Thanks

+2  A: 

No, there are non. From my experience .net can't be used to create real time systems for many reasons, not only about garbage collection. C or C++ are better choice. Also modern OSes do not provide deterministic scheduling, and it is about all applications, regardless of language.

Andrey
+3  A: 

There is no way to make the GC deterministic, expect of course from calling GC.Collect() exactly every second using a timer ;-).

The GC however does contain a notification mechanism (since .NET 3.5 SP1) that allows you to be notified when a gen 2 collect is about to happen. You can read about it here.

The GC now also contains multiple latency modes that make it possible to prevent any GC collects from occurring. Of course you should be very careful with this, but is especially useful for real-time systems. You can read more about it here.

Steven
Excellent idea. I've put GC.Collect() on the 250ms timer. Thanks a bunch.
DayOne
Just to add, this doesn't make it deterministic - it can still call itself whenever it likes and you've no idea what it will GC, or how long it will take. And your timer is not going to be able to tick *exactly* every 250ms.
Adam
I hoped the smiley at the end of that sentence made it clear that I wasn't serious. But seriously, calling `GC.Collect()` every 250 ms. is a very bad idea. While having the collects at deterministic intervals, you would have very bad performance because you trigger many gen 2 collects.
Steven
@DayOne: That sounds like a *really* bad idea. By calling GC.Collect like that you will force the most expensive type of collection on a regular basis. You application will spend more time collecting than it needs to. Keep in mind that all your user threads are suspended during parts of the collection.
Brian Rasmussen
A: 

You would have to control the GC yourself in order to get predictable real-time behaviour, but if you are doing this then you may as well not use a managed language.

For real-time systems you need control over everything that is running. There are third-party modifications to Windows XP that make it real-time (can't remember if it's soft or hard real-time though).

Completely unfeasible option. Look into Cosmos OS - written in C# and compiled to assembler I think - might be able to do something with that :)

Adam