@@ -158,6 +158,7 @@ internal static void Initialize(bool initSigs = false)
158158 ClassManager . Reset ( ) ;
159159 ClassDerivedObject . Reset ( ) ;
160160 TypeManager . Initialize ( ) ;
161+ CLRObject . creationBlocked = false ;
161162 _typesInitialized = true ;
162163
163164 // Initialize modules that depend on the runtime class.
@@ -278,6 +279,10 @@ internal static void Shutdown()
278279 ClearClrModules ( ) ;
279280 RemoveClrRootModule ( ) ;
280281
282+ TryCollectingGarbage ( MaxCollectRetriesOnShutdown , forceBreakLoops : true ,
283+ obj : true , derived : false , buffer : false ) ;
284+ CLRObject . creationBlocked = true ;
285+
281286 NullGCHandles ( ExtensionType . loadedExtensions ) ;
282287 ClassManager . RemoveClasses ( ) ;
283288 TypeManager . RemoveTypes ( ) ;
@@ -295,8 +300,7 @@ internal static void Shutdown()
295300 PyObjectConversions . Reset ( ) ;
296301
297302 PyGC_Collect ( ) ;
298- bool everythingSeemsCollected = TryCollectingGarbage ( MaxCollectRetriesOnShutdown ,
299- forceBreakLoops : true ) ;
303+ bool everythingSeemsCollected = TryCollectingGarbage ( MaxCollectRetriesOnShutdown ) ;
300304 Debug . Assert ( everythingSeemsCollected ) ;
301305
302306 Finalizer . Shutdown ( ) ;
@@ -328,7 +332,8 @@ internal static void Shutdown()
328332
329333 const int MaxCollectRetriesOnShutdown = 20 ;
330334 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 )
332337 {
333338 if ( runs <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( runs ) ) ;
334339
@@ -341,7 +346,9 @@ static bool TryCollectingGarbage(int runs, bool forceBreakLoops)
341346 GC . Collect ( ) ;
342347 GC . WaitForPendingFinalizers ( ) ;
343348 pyCollected += PyGC_Collect ( ) ;
344- pyCollected += Finalizer . Instance . DisposeAll ( ) ;
349+ pyCollected += Finalizer . Instance . DisposeAll ( disposeObj : obj ,
350+ disposeDerived : derived ,
351+ disposeBuffer : buffer ) ;
345352 }
346353 if ( Volatile . Read ( ref _collected ) == 0 && pyCollected == 0 )
347354 {
0 commit comments