forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalize.cs
More file actions
58 lines (48 loc) · 1.25 KB
/
Finalize.cs
File metadata and controls
58 lines (48 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Tests Finalize() and WaitForPendingFinalizers()
using System;
using System.Runtime.CompilerServices;
public class Test
{
public static bool visited = false;
public class Dummy
{
~Dummy()
{
Console.WriteLine("In Finalize() of Dummy");
Test.visited = true;
}
}
public class CreateObj
{
public Dummy obj;
public CreateObj()
{
obj = new Dummy();
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public void RunTest()
{
obj = null;
}
}
public static int Main()
{
CreateObj temp = new CreateObj();
temp.RunTest();
GC.Collect();
GC.WaitForPendingFinalizers(); // makes sure Finalize() is called.
GC.Collect();
if (visited)
{
Console.WriteLine("Test for Finalize() & WaitForPendingFinalizers() passed!");
return 100;
}
else
{
Console.WriteLine("Test for Finalize() & WaitForPendingFinalizers() failed!");
return 0;
}
}
}