浏览代码

incremental gc

/siyaoH-1.17-debugDraw
siyao 3 年前
当前提交
6a76d3ae
共有 1 个文件被更改,包括 33 次插入0 次删除
  1. 33
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs

33
com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs


using System.Collections.Generic;
using Unity.UIWidgets.external.simplejson;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using UnityEngine.Profiling;
using UnityEngine.Scripting;
using UnityEngine.UI;
using RawImage = UnityEngine.UI.RawImage;

}
}
// 8 MB
const long kCollectAfterAllocating = 8 * 1024 * 1024;
long lastFrameMemory = 0;
long nextCollectAt = 0;
protected virtual void Update() {
if (!_viewMetricsCallbackRegistered) {
_viewMetricsCallbackRegistered = true;

CollectGarbegeOndemend();
void CollectGarbegeOndemend() {
long mem = Profiler.GetMonoUsedSizeLong();
if (mem < lastFrameMemory)
{
// GC happened.
nextCollectAt = mem + kCollectAfterAllocating;
}
else if (mem >= nextCollectAt)
{
// Trigger incremental GC
GarbageCollector.CollectIncremental(1000);
lastFrameMemory = mem + kCollectAfterAllocating;
}
lastFrameMemory = mem;
}
#if !UNITY_EDITOR && UNITY_ANDROID
bool AndroidInitialized = true;

//the hook API cannot be automatically called on IOS, so we need try hook it here
Hooks.tryHook();
#endif
#if !UNITY_EDITOR
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
#endif
Application.lowMemory += GC.Collect;
base.OnEnable();
D.assert(_wrapper == null);

正在加载...
取消
保存