Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Bear in mind that that article is from 2003, which was using CLR v1. We're now on CLR v4 (although there was no v3) so I'm not entirely surprised you don't see exactly the same behaviour.</p> <p>Currently I can't even get to the linked page, and you haven't included a description of what the page describes. Is it the possibility of an object being garbage collected before the end of an instance method?</p> <p>If so, the most obvious reason you might have problems reproducing it is if you're using the debugger. The garbage collector is <em>much</em> more aggressive when you're running without a debugger attached.</p> <p>Here's a short but complete program which demonstrates the issue when running not in a debugger:</p> <pre><code>using System; class ClassWithFinalizer { private int value; public ClassWithFinalizer(int value) { this.value = value; } ~ClassWithFinalizer() { Console.WriteLine("Finalizer running!"); } public void ShowValue() { Console.WriteLine(value); Console.WriteLine("Calling GC.Collect()"); GC.Collect(); Console.WriteLine("Calling GC.WaitForPendingFinalizers()"); GC.WaitForPendingFinalizers(); Console.WriteLine("End of method"); } } class Test { static void Main() { var x = new ClassWithFinalizer(10); x.ShowValue(); } } </code></pre> <p>Compilation (optimized and without debug symbols, just to give it the best chance!):</p> <pre><code>csc /o+ /debug- Test.cs </code></pre> <p>Now run, with output:</p> <pre><code>c:\users\Jon\Test&gt;test 10 Calling GC.Collect() Calling GC.WaitForPendingFinalizers() Finalizer running! End of method </code></pre> <p>Note how the finalizer runs before the method has completed.</p> <p>Tested with .NET 4 and .NET 3.5.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload