@@ -12,6 +12,7 @@ class GCHeapEnumerationTests
1212 {
1313 static readonly string ShouldSetMonitorGCEventMaskEnvVar = "Set_Monitor_GC_Event_Mask" ;
1414 static readonly Guid GCHeapEnumerationProfilerGuid = new Guid ( "8753F0E1-6D6D-4329-B8E1-334918869C15" ) ;
15+ static List < object > _rootObjects = new List < object > ( ) ;
1516
1617 [ DllImport ( "Profiler" ) ]
1718 private static extern void EnumerateGCHeapObjects ( ) ;
@@ -27,14 +28,14 @@ class GCHeapEnumerationTests
2728
2829 public static int EnumerateGCHeapObjectsSingleThreadNoPriorSuspension ( )
2930 {
30- var _ = new CustomGCHeapObject ( ) ;
31+ _rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
3132 EnumerateGCHeapObjects ( ) ;
3233 return 100 ;
3334 }
3435
3536 public static int EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ( )
3637 {
37- var _ = new CustomGCHeapObject ( ) ;
38+ _rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
3839 SuspendRuntime ( ) ;
3940 EnumerateGCHeapObjects ( ) ;
4041 ResumeRuntime ( ) ;
@@ -43,6 +44,7 @@ public static int EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRunti
4344
4445 public static int EnumerateGCHeapObjectsInBackgroundThreadWithRuntimeSuspension ( )
4546 {
47+ _rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
4648 EnumerateHeapObjectsInBackgroundThread ( ) ;
4749 GC . Collect ( ) ;
4850 return 100 ;
@@ -63,7 +65,7 @@ public static int EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspensio
6365 {
6466 startEvent . WaitOne ( ) ;
6567 Thread . Sleep ( 1000 ) ;
66- var _ = new CustomGCHeapObject ( ) ;
68+ _rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
6769 EnumerateGCHeapObjects ( ) ;
6870 } ) ;
6971 enumerateThread . Name = "EnumerateGCHeapObjects" ;
0 commit comments