This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
tests/src/GC/Scenarios/FinalizeTimeout Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public static int Main(string[] args)
17
17
do
18
18
{
19
19
finalizableObject = new BlockingFinalizerOnShutdown ( ) ;
20
+ GC . KeepAlive ( finalizableObject ) ;
20
21
} while ( ! BlockingFinalizerOnShutdown . finalizerCompletedOnce ) ;
21
22
22
23
// Start a bunch of threads that allocate continuously, to increase the chance that when Main returns, one of the
@@ -42,12 +43,15 @@ private static void ThreadMain()
42
43
{
43
44
byte [ ] b ;
44
45
while ( true )
46
+ {
45
47
b = new byte [ 1024 ] ;
48
+ GC . KeepAlive ( b ) ;
49
+ }
46
50
}
47
51
48
52
private class BlockingFinalizerOnShutdown
49
53
{
50
- public static bool finalizerCompletedOnce = false ;
54
+ public volatile static bool finalizerCompletedOnce = false ;
51
55
public bool isLastObject = false ;
52
56
53
57
~ BlockingFinalizerOnShutdown ( )
@@ -68,6 +72,7 @@ private class BlockingFinalizerOnShutdown
68
72
do
69
73
{
70
74
o = new object ( ) ;
75
+ GC . KeepAlive ( o ) ;
71
76
} while ( ( ++ i & 0xff ) != 0 || ( elapsed = DateTime . Now - start ) < timeout ) ;
72
77
73
78
Console . WriteLine ( "Finalizer end" ) ;
You can’t perform that action at this time.
0 commit comments