Skip to content

Commit

Permalink
This should be good for master
Browse files Browse the repository at this point in the history
  • Loading branch information
Mag-nus committed Feb 2, 2024
1 parent c178102 commit bea1d76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Source/ACE.Server/Command/Handlers/DeveloperCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2212,14 +2212,20 @@ public static void HandleClearPhysicsCaches(Session session, params string[] par

[CommandHandler("forcegc", AccessLevel.Developer, CommandHandlerFlag.None, 0, "Forces .NET Garbage Collection")]
public static void HandleForceGC(Session session, params string[] parameters)
{
GC.Collect();
}

[CommandHandler("forcegc2", AccessLevel.Developer, CommandHandlerFlag.None, 0, "Forces .NET Garbage Collection with LOH Compact")]
public static void HandleForceGC2(Session session, params string[] parameters)
{
// https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.gcsettings.largeobjectheapcompactionmode
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;

GC.Collect();

CommandHandlerHelper.WriteOutputInfo(session, ".NET Garbage Collection forced");
CommandHandlerHelper.WriteOutputInfo(session, ".NET Garbage Collection forced with LOH Compact");
}

[CommandHandler("auditobjectmaint", AccessLevel.Developer, CommandHandlerFlag.None, 0, "Iterates over physics objects to find leaks")]
Expand Down
9 changes: 8 additions & 1 deletion Source/ACE.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Threading;

Expand Down Expand Up @@ -314,8 +315,14 @@ public static void Main(string[] args)

// Free up memory before the server goes online. This can free up 6 GB+ on larger servers.
log.Info("Forcing .net garbage collection...");
for (int i = 0 ; i < 10 ; i++)
for (int i = 0; i < 10; i++)
{
// https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.gcsettings.largeobjectheapcompactionmode
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;

GC.Collect();
}

// This should be last
log.Info("Initializing CommandManager...");
Expand Down

0 comments on commit bea1d76

Please sign in to comment.