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

Commit 5e2c321

Browse files
disable incremental gc by default
1 parent 7dfae0c commit 5e2c321

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

README-ZH.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ UIWidgets也支持Gif!
205205
#### 八、移动设备优化
206206
目前在默认情况下,为了保证流畅度,项目在各个平台上均会以最高的刷新频率运行。不过您可以通过在代码中设置```UIWidgetsGlobalConfiguration.EnableAutoAdjustFramerate = true```的方式来开启自动降帧的功能:该功能开启后,在UI内容不变的情况下我们将降低项目的刷新率来降低耗电。
207207

208-
在移动设备上UI绘制的流畅度受到GC影响较大。项目默认会开启OnDemandGC来接管并优化整体GC效果。如果您不需要GC被UIWidgets控制,请在代码中设置```UIWidgetsGlobalConfiguration.EnableIncrementalGC = false```。
209-
208+
在移动设备上UI绘制的流畅度受到GC影响较大。如有卡顿,例如滑动掉帧。可开启OnDemandGC, UIWidgets将接管并优化整体GC效果,请在代码中设置```UIWidgetsGlobalConfiguration.EnableIncrementalGC = true```,并开启```Project Setting -> Player -> Other Settings -> Use incremental GC```。
210209

211210
## 调试UIWidgets应用程序
212211

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Please put images under StreamingAssets folder, a and loading it using ```Image.
216216
#### Performance Optimization on Mobile devices
217217
By setting ```UIWidgetsGlobalConfiguration.EnableAutoAdjustFramerate = true``` in your project, UIWidgets will drop the frame rate of your App to 0 if the UI contents of UIWidgetsPanel is not changed for some time. This will help to prevent battery drain on mobile devices significantly. Note that this feature is disabled by default.
218218

219-
Long time garbage collection may cause App to stuck frequently. In UIWidgets we enable incremental garbage collection to avoid it. However, you can disable this feature by setting ```UIWidgetsGlobalConfiguration.EnableIncrementalGC = false```.
219+
Long time garbage collection may cause App to stuck frequently. You can enable incremental garbage collection to avoid it. You can enable this feature by setting ```UIWidgetsGlobalConfiguration.EnableIncrementalGC = true```, and enabling ```Project Setting -> Player -> Other Settings -> Use incremental GC```.
220220

221221
## Debug UIWidgets Application
222222

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static class UIWidgetsGlobalConfiguration {
44
public static bool EnableAutoAdjustFramerate = false;
55

66
//enable incremental gc by default
7-
public static bool EnableIncrementalGC = true;
7+
public static bool EnableIncrementalGC = false;
88

99
//disable debug at runtime by default
1010
public static bool EnableDebugAtRuntime = false;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ void TryEnableOnDemandGC()
180180
}
181181
}
182182

183+
void TryDisableOnDemandGC()
184+
{
185+
if (UIWidgetsGlobalConfiguration.EnableIncrementalGC)
186+
{
187+
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;
188+
}
189+
}
190+
183191
void CollectGarbageOnDemand()
184192
{
185193
if (!UIWidgetsGlobalConfiguration.EnableIncrementalGC)
@@ -272,6 +280,9 @@ protected override void OnDisable() {
272280
_wrapper = null;
273281
texture = null;
274282
Input_OnDisable();
283+
#if !UNITY_EDITOR
284+
TryDisableOnDemandGC();
285+
#endif
275286
base.OnDisable();
276287
}
277288

0 commit comments

Comments
 (0)