blob: ffa7eaa6cb52ae0aa40ab306396e94fbc8f43393 (
plain)
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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// Tests GCHandleType.Normal .. the object with GCHandleType Normal
// should not be collected.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public class Test {
public class Dummy {
public static int flag=0;
~Dummy() {
Console.WriteLine("In Finalize() of Dummy");
flag=99;
}
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void RunTest()
{
Dummy obj = new Dummy();
Console.WriteLine("Allocating a normal handle to object..");
GCHandle handle = GCHandle.Alloc(obj,GCHandleType.Normal); // Normal handle
// ensuring that GC happens even with /debug mode
obj=null;
}
public static int Main() {
RunTest();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
if(Dummy.flag == 0) {
Console.WriteLine("Test for GCHandleType.Normal passed!");
return 100;
}
else {
Console.WriteLine("Test for GCHandleType.Normal failed!");
return 1;
}
}
}
|