Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Skip garbage collection on process shutdown
  • Loading branch information
filmor committed Sep 23, 2023
commit 8f5a8503d16cc0703e6fef189fd26e9d33b55019
22 changes: 14 additions & 8 deletions src/runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,26 @@ internal static void Shutdown()
DisposeLazyObject(hexCallable);
PyObjectConversions.Reset();

PyGC_Collect();
bool everythingSeemsCollected = TryCollectingGarbage(MaxCollectRetriesOnShutdown,
forceBreakLoops: true);
Debug.Assert(everythingSeemsCollected);
if (!ProcessIsTerminating)
{
PyGC_Collect();
bool everythingSeemsCollected = TryCollectingGarbage(MaxCollectRetriesOnShutdown,
forceBreakLoops: true);
Debug.Assert(everythingSeemsCollected);
}

ResetPyMembers();
Finalizer.Shutdown();
InternString.Shutdown();

ResetPyMembers();

if (!HostedInPython)
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (!ProcessIsTerminating)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}

PyGILState_Release(state);
// Then release the GIL for good, if there is somehting to release
// Use the unchecked version as the checked version calls `abort()`
Expand Down