Forcing the garbage collector (2)

OK some updates that I have to share.

1) GC modes

If you add this setting to the app.config file and you have more that one physical CPU/core you get different GC behaviour.

    <gcServer enabled="true" />

This puts the GC on the other core, that has some interesting effects on memory and CPU. This is similar to Java VMs but I didn’t really think about it for .NET.


you can see the CPU spikes as well as the different memory graph. Unsurprisingly this changes the throughput as well and you don’t get the “bad polls” nearly so much. Overall, thoroughput is improved as well as latency.

2) garbage collection spy class

Add this class:

    class GCNotifier
            new GCNotifier();

and initialise it somewhere in main

static void Main(string[] args)
	new GCNotifier();
	. . .

then it will be touched each time a GC runs and you will see a console message although not necessarily at the same time as the GC and finalizer are on different threads. It is also a really cunning piece of code (not written by me).

Here is an excellent post on GC “secrets” from a blog I’ve not seen before, but now on my list

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s