Ok...RTFM got me again:

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemObjectClas
sFinalizeTopic.asp

The problem we were having was that the # of finalizers during teardown
of our process was going up.  In that case (as the docs say), the
finalization gives up (since it may never finish if the finalization has
recursion or something else nasty).  Here is an example,  obviously
something you'd never really do, that demonstrated the behavior[1].


Thanks,

Shawn Wildermuth
[EMAIL PROTECTED]
http://adoguy.com
http://adoguy.com/book
http://shawnwildermuth.com

[1]
using System;
using System.IO;

namespace TestMissingFinalizers
{
  class Class1
  {
    static public int iterations = 1000;

    [STAThread]
    static void Main(string[] args)
    {
      int iter = iterations;
      for (int x = 0; x < iter; ++x)
      {
        // Create a new Instance
        // to be collected as soon
        // as possible
        new Foo(x);
      }
    }
  }

  public class Foo
  {
    public Foo(int number)
    {
      _number = number;
    }

    int _number;

    ~Foo()
    {
      // The tolerance is pretty high
      // so it takes quite a lot of
      // new finalizers for it to
      // bail out.
      for (int x = 0; x < 10000; ++x)
      {
        new Bar();
      }

      // Write out to see our results
      // Write out the number of collections
      // that happen
      Console.WriteLine("Number Uncollected: {0}",
        --Class1.iterations);
    }
  }

  public class Bar
  {
    ~Bar()
    {
    }

    int x = 0;
  }
}

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to