mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 01:10:45 -05:00
Basic memory manager (!177)
Attempt at slowing down the memory leak caused by bots spawning/dying Co-authored-by: Cj <161484149+CJ-SPT@users.noreply.github.com> Reviewed-on: SPT/Modules#177 Co-authored-by: Cj <cj@noreply.dev.sp-tarkov.com> Co-committed-by: Cj <cj@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
d58f48fc3e
commit
1a08680bdd
@ -5,15 +5,19 @@ using SPT.Custom.Utils;
|
|||||||
using SPT.Reflection.Utils;
|
using SPT.Reflection.Utils;
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using BepInEx.Logging;
|
||||||
|
|
||||||
namespace SPT.Custom
|
namespace SPT.Custom
|
||||||
{
|
{
|
||||||
[BepInPlugin("com.SPT.custom", "SPT.Custom", SPTPluginInfo.PLUGIN_VERSION)]
|
[BepInPlugin("com.SPT.custom", "SPT.Custom", SPTPluginInfo.PLUGIN_VERSION)]
|
||||||
public class SPTCustomPlugin : BaseUnityPlugin
|
public class SPTCustomPlugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
|
internal static ManualLogSource Log;
|
||||||
|
|
||||||
public void Awake()
|
public void Awake()
|
||||||
{
|
{
|
||||||
Logger.LogInfo("Loading: SPT.Custom");
|
Logger.LogInfo("Loading: SPT.Custom");
|
||||||
|
Log = Logger;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -44,6 +48,7 @@ namespace SPT.Custom
|
|||||||
//new AllowAirdropsInPvEPatch().Enable();
|
//new AllowAirdropsInPvEPatch().Enable();
|
||||||
|
|
||||||
HookObject.AddOrGetComponent<MenuNotificationManager>();
|
HookObject.AddOrGetComponent<MenuNotificationManager>();
|
||||||
|
HookObject.AddOrGetComponent<MemoryManager>();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
36
project/SPT.Custom/Utils/MemoryManager.cs
Normal file
36
project/SPT.Custom/Utils/MemoryManager.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Scripting;
|
||||||
|
|
||||||
|
namespace SPT.Custom.Utils;
|
||||||
|
|
||||||
|
public class MemoryManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
private WaitForSecondsRealtime _gcCollectionTime = new(30f);
|
||||||
|
|
||||||
|
public void Awake()
|
||||||
|
{
|
||||||
|
StartCoroutine(MemoryManagerCoroutine());
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator MemoryManagerCoroutine()
|
||||||
|
{
|
||||||
|
yield return _gcCollectionTime;
|
||||||
|
|
||||||
|
// SPTCustomPlugin.Log.LogDebug($"Allocated Mananged Memory {GC.GetTotalMemory(false) / 1024f / 1024f} MB");
|
||||||
|
|
||||||
|
Task.Run(CollectMemory);
|
||||||
|
|
||||||
|
StartCoroutine(MemoryManagerCoroutine());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task CollectMemory()
|
||||||
|
{
|
||||||
|
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;
|
||||||
|
GC.Collect(2, GCCollectionMode.Optimized, false, false);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user