[Mono-dev] GC Question.

Bill Holmes billholmes54 at gmail.com
Mon Mar 10 23:29:01 EDT 2008


I did not want to file a bug on this just yet as it may be related to
https://bugzilla.novell.com/show_bug.cgi?id=319247 .  Or it just may
be a bad test case.

The following code under MS.net displays

_activeCount = 1
_activeCount = 0

Where mono displays

_activeCount = 1
_activeCount = 1

Should I file a bug report on this?

thanks
-bill

using System;

public class Test
{
	private static int _activeCount = 0;

	Test ()
	{
		System.Threading.Interlocked.Increment (ref _activeCount);
	}

	~Test ()
	{
		// are we allowed to do this in a finaliser?
		System.Threading.Interlocked.Decrement (ref _activeCount);
	}

	[STAThread]
	static void Main (string[] args)
	{
		if (args.Length == 0)
		{
			Test test = new Test ();
			Console.WriteLine ("_activeCount = " + _activeCount);
			GC.KeepAlive (test);
			test = null;
		}

		GC.Collect ();
		GC.WaitForPendingFinalizers ();

		Console.WriteLine ("_activeCount = " + _activeCount);
	}
}


More information about the Mono-devel-list mailing list