|
|
|
|
|
|
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); |
|
|
|