Wednesday, 24 September 2008

Is Java GC really better than C# GC? NO WAY! Java just hints, C# actually DOES stuff!

JAVA way: System.gc() -> Runtime.getRuntime().gc() - this is just a "hint" to JVM to do some cleanup
C# way: GC.Collect() -> this is a "command" to CLR, "clean up your act!" This will run all eligible object finalizers on a separate thread. Another important method is GC.WaitForPendingFinalizers, usually you call this after a GC.Collect. It makes a difference to the memory used by your program! You can also run a GC.Collect on a specific generation (generation 0 being the most recently allocated objects).

No comments: