Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit 7dfae0c

Browse files
fix gc
1 parent 521eafb commit 7dfae0c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ void TryEnableOnDemandGC()
177177
if (UIWidgetsGlobalConfiguration.EnableIncrementalGC)
178178
{
179179
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
180-
Application.lowMemory += GC.Collect;
181180
}
182181
}
183182

@@ -197,8 +196,10 @@ void CollectGarbageOnDemand()
197196
else if (mem >= nextCollectAt)
198197
{
199198
// Trigger incremental GC
199+
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;
200200
GarbageCollector.CollectIncremental(1000);
201201
lastFrameMemory = mem + kCollectAfterAllocating;
202+
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
202203
}
203204

204205
lastFrameMemory = mem;
@@ -238,6 +239,12 @@ protected void OnEnable() {
238239
#if !UNITY_EDITOR
239240
TryEnableOnDemandGC();
240241
#endif
242+
Application.lowMemory += () => {
243+
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;
244+
GC.Collect();
245+
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
246+
};
247+
241248

242249
base.OnEnable();
243250

0 commit comments

Comments
 (0)