@@ -18,7 +18,7 @@ public class DisposeScopeManager
18
18
internal ThreadDisposeScopeStatistics StatisticsInstance { get ; } = new ThreadDisposeScopeStatistics ( ) ;
19
19
20
20
internal static DisposeScopeManager ThreadSingleton => ( _threadSingleton ??= new DisposeScopeManager ( ) ) ;
21
- internal Stack < DisposeScope > DisposeScopeStack { get ; } = new ( ) ;
21
+ internal List < DisposeScope > DisposeScopeStack { get ; } = new ( ) ;
22
22
23
23
public static ThreadDisposeScopeStatistics Statistics => ThreadSingleton . StatisticsInstance ;
24
24
@@ -30,7 +30,7 @@ public class DisposeScopeManager
30
30
}
31
31
32
32
StatisticsInstance . CreatedInScopeCount ++ ;
33
- var current = DisposeScopeStack . Peek ( ) ;
33
+ var current = DisposeScopeStack [ DisposeScopeStack . Count - 1 ] ;
34
34
current . Include ( disposable ) ;
35
35
return current ;
36
36
}
@@ -42,15 +42,15 @@ internal static DisposeScope NewDisposeScope()
42
42
43
43
internal void RemoveDisposeScope ( DisposeScope disposeScope )
44
44
{
45
- Debug . Assert ( DisposeScopeStack . Count > 0 ) ;
46
- Debug . Assert ( DisposeScopeStack . Peek ( ) == disposeScope ) ;
47
- DisposeScopeStack . Pop ( ) ;
45
+ var index = DisposeScopeStack . LastIndexOf ( disposeScope ) ;
46
+ if ( index is not - 1 )
47
+ DisposeScopeStack . RemoveAt ( index ) ;
48
48
}
49
49
50
50
private DisposeScope InnerNewDisposeScope ( )
51
51
{
52
52
var disposeScope = new DisposeScope ( this ) ;
53
- DisposeScopeStack . Push ( disposeScope ) ;
53
+ DisposeScopeStack . Add ( disposeScope ) ;
54
54
return disposeScope ;
55
55
}
56
56
}
0 commit comments