GC.Collect () не собирает сразу?
В ходе обсуждения в чате я написал это консольное приложение.
Code:using System;
class Program
{
static void Main(string[] args)
{
CreateClass();
Console.Write("Collecting... ");
GC.Collect();
Console.WriteLine("Done");
}
static void CreateClass()
{
SomeClass c = new SomeClass();
}
}
class SomeClass
{
~SomeClass()
{
throw new Exception();
}
}
Result:
Collecting... Done
Unhandled Exception: System.Exception: Exception of type 'System.Exception' was
thrown.
at SomeClass.Finalize()
Я ожидал, что приложение вылетитbefore Done
был напечатан.
Меня не волнует, как это сделать. Мой вопросwhy doesn't it?