Last active
November 8, 2017 15:46
-
-
Save EgorBo/ce2e7aca568ef60bec1da78aba621668 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Xunit; | |
namespace ConsoleApp7 | |
{ | |
public class FinalizerTest | |
{ | |
static void AllocAndLeaveScope() | |
{ | |
new TestClass(); | |
} | |
[Fact] | |
public void CanBeFinalized() | |
{ | |
AllocAndLeaveScope(); | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
if (!TestClass.isFinalized) | |
throw new InvalidOperationException(); | |
} | |
} | |
public class TestClass | |
{ | |
public static bool isFinalized; | |
~TestClass() | |
{ | |
isFinalized = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment