Shawn, Everything's working fine, you just tripped over a variable access synchronization issue. In ~Foo, you decrement the variable that is being used as a loop counter in Main, and that screws up the loop counting as C# fully re-evaluates the condition at every loop.
Insert the line "int iter = iterations;" just before the loop, then use iter instead of iterations as the loop counter -- now the output counts down to zero. Not defining ADDSTREAM probably just caused the collector thread not to get any cycles before the loop was finished, hence the counter couldn't be manipulated. Cheers, Chris At 21:53 18.09.2002 -0400, you wrote: >Hopefully I am missing something. I have this small example of >finalizers not being called as a process is being torn down.[1] Does >anyone know if this is expected behavior? > >Thanks, > >Shawn Wildermuth >[EMAIL PROTECTED] >http://adoguy.com >http://adoguy.com/book >http://shawnwildermuth.com > >[1]: > >// test.cs > >// Definition to add or remove the >// stream reference (which causes >// some of the finalizers to >// be lost) >#define ADDSTREAM > >using System; >using System.IO; > >namespace TestMissingFinalizers >{ > class Class1 > { > static public int iterations = 1000; > > [STAThread] > static void Main(string[] args) > { > for (int x = 0; x < iterations; ++x) > { > // Create a new Instance > // to be collected as soon > // as possible > new Foo(x); > } > } > } > > public class Foo > { > public Foo(int number) > { >#if ADDSTREAM > // Open a Text Stream > // This will cause theFinalizer to not be > // called on every instance > string fileName = string.Format("foo{0}.txt", number); > strm = new FileStream(fileName, FileMode.Create); >#endif > } > >#if ADDSTREAM > private FileStream strm; >#endif > > ~Foo() > { >#if ADDSTREAM > // If we close the stream > strm.Close(); >#endif > // Write out to see our results > // Write out the number of collections > // that happen > Console.WriteLine("Number Uncollected: {0}", > --Class1.iterations); > } > } >} > >You can read messages from the Advanced DOTNET archive, unsubscribe from >Advanced DOTNET, or >subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.