Skip to content

Commit

Permalink
feat: ForceCollect
Browse files Browse the repository at this point in the history
  • Loading branch information
KillStr3aK committed Oct 10, 2024
1 parent 6d1af88 commit 01eac8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions managed/CounterStrikeSharp.API/Core/Memory/IMemoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ public interface IMemoryManager
public void Stop(bool forceStop = false);

public void Resume();

public void ForceCollect(int generation, GCCollectionMode mode, bool blocking);
}
}
7 changes: 6 additions & 1 deletion managed/CounterStrikeSharp.API/Core/Memory/MemoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ public void Resume()
_logger.LogInformation("Service has been resumed");
}

public void ForceCollect(int generation, GCCollectionMode mode, bool blocking)
{
GC.Collect(generation, mode, blocking);
}

private void BackgroundThread()
{
_logger.LogInformation("Service has been started");
Expand Down Expand Up @@ -287,7 +292,7 @@ private void BackgroundThread()
DateTime startTime = DateTime.UtcNow;

// some may go to gen1 or even gen2, but even those are released when this nondeterministic wonder wants so
GC.Collect(0, GCCollectionMode.Default, true);
ForceCollect(0, GCCollectionMode.Default, true);

// this might be obsolete with 'blocking: false'?
GC.WaitForPendingFinalizers();
Expand Down

0 comments on commit 01eac8b

Please sign in to comment.