@@ -158,6 +158,7 @@ internal static void Initialize(bool initSigs = false)
158
158
ClassManager . Reset ( ) ;
159
159
ClassDerivedObject . Reset ( ) ;
160
160
TypeManager . Initialize ( ) ;
161
+ CLRObject . creationBlocked = false ;
161
162
_typesInitialized = true ;
162
163
163
164
// Initialize modules that depend on the runtime class.
@@ -278,6 +279,10 @@ internal static void Shutdown()
278
279
ClearClrModules ( ) ;
279
280
RemoveClrRootModule ( ) ;
280
281
282
+ TryCollectingGarbage ( MaxCollectRetriesOnShutdown , forceBreakLoops : true ,
283
+ obj : true , derived : false , buffer : false ) ;
284
+ CLRObject . creationBlocked = true ;
285
+
281
286
NullGCHandles ( ExtensionType . loadedExtensions ) ;
282
287
ClassManager . RemoveClasses ( ) ;
283
288
TypeManager . RemoveTypes ( ) ;
@@ -295,8 +300,7 @@ internal static void Shutdown()
295
300
PyObjectConversions . Reset ( ) ;
296
301
297
302
PyGC_Collect ( ) ;
298
- bool everythingSeemsCollected = TryCollectingGarbage ( MaxCollectRetriesOnShutdown ,
299
- forceBreakLoops : true ) ;
303
+ bool everythingSeemsCollected = TryCollectingGarbage ( MaxCollectRetriesOnShutdown ) ;
300
304
Debug . Assert ( everythingSeemsCollected ) ;
301
305
302
306
Finalizer . Shutdown ( ) ;
@@ -328,7 +332,8 @@ internal static void Shutdown()
328
332
329
333
const int MaxCollectRetriesOnShutdown = 20 ;
330
334
internal static int _collected ;
331
- static bool TryCollectingGarbage ( int runs , bool forceBreakLoops )
335
+ static bool TryCollectingGarbage ( int runs , bool forceBreakLoops ,
336
+ bool obj = true , bool derived = true , bool buffer = true )
332
337
{
333
338
if ( runs <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( runs ) ) ;
334
339
@@ -341,7 +346,9 @@ static bool TryCollectingGarbage(int runs, bool forceBreakLoops)
341
346
GC . Collect ( ) ;
342
347
GC . WaitForPendingFinalizers ( ) ;
343
348
pyCollected += PyGC_Collect ( ) ;
344
- pyCollected += Finalizer . Instance . DisposeAll ( ) ;
349
+ pyCollected += Finalizer . Instance . DisposeAll ( disposeObj : obj ,
350
+ disposeDerived : derived ,
351
+ disposeBuffer : buffer ) ;
345
352
}
346
353
if ( Volatile . Read ( ref _collected ) == 0 && pyCollected == 0 )
347
354
{
0 commit comments