Skip to content

Commit

Permalink
⚡ Force GC collection at the end of Engine constructor and after `u…
Browse files Browse the repository at this point in the history
…cinewgame` (#685)
  • Loading branch information
eduherminio committed Feb 27, 2024
1 parent 10777a2 commit 57a9b0f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Lynx/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public Engine(ChannelWriter<string> engineWriter)

_engineWriter = engineWriter;
ResetEngine();
# endif
#endif

#pragma warning disable S1215 // "GC.Collect" should not be called
GC.Collect();
GC.WaitForPendingFinalizers();
#pragma warning restore S1215 // "GC.Collect" should not be called
}

#pragma warning disable S1144 // Unused private types or members should be removed - used in Release mode
Expand Down Expand Up @@ -121,6 +126,11 @@ public void NewGame()
_isNewGameCommandSupported = true;

ResetEngine();

#pragma warning disable S1215 // "GC.Collect" should not be called
GC.Collect();
GC.WaitForPendingFinalizers();
#pragma warning restore S1215 // "GC.Collect" should not be called
}

public void AdjustPosition(ReadOnlySpan<char> rawPositionCommand)
Expand Down

0 comments on commit 57a9b0f

Please sign in to comment.