0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 01:50:45 -05:00
modules/project/SPT.Custom/Patches/MemoryCollectionPatch.cs
Cj 25801e3eda GC refactor (!178)
Make the GC only run on show inventory screen, and only allow it to run for a maximum of 25 milliseconds at a time.

Co-authored-by: Cj <161484149+CJ-SPT@users.noreply.github.com>
Reviewed-on: SPT/Modules#178
Co-authored-by: Cj <cj@noreply.dev.sp-tarkov.com>
Co-committed-by: Cj <cj@noreply.dev.sp-tarkov.com>
2024-11-21 08:54:45 +00:00

29 lines
787 B
C#

using System.Reflection;
using Comfort.Common;
using EFT;
using EFT.UI;
using EFT.UI.Screens;
using HarmonyLib;
using SPT.Reflection.Patching;
using UnityEngine.Scripting;
namespace SPT.Custom.Patches;
public class MemoryCollectionPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(MenuTaskBar), nameof(MenuTaskBar.OnScreenChanged));
}
[PatchPostfix]
public static void PatchPostfix(EEftScreenType eftScreenType)
{
if (eftScreenType != EEftScreenType.Inventory || !Singleton<GameWorld>.Instantiated) return;
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;
// 25000000 Nanoseconds is 25 Milliseconds.
GarbageCollector.CollectIncremental(25000000L);
}
}