0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 07:10:44 -05:00
modules/project/SPT.Custom/Utils/MemoryManager.cs

36 lines
863 B
C#

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, true);
return Task.CompletedTask;
}
}