Skip to content

Commit

Permalink
更新hotreload文档关于 RuntimeApi.EnableLiveObjectValidation的说明
Browse files Browse the repository at this point in the history
  • Loading branch information
pirunxi committed May 24, 2024
1 parent 1b7866b commit 594b8aa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 1 addition & 2 deletions docs/business/reload/hotreloadassembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@
实际工程可能很复杂,开发者找出所有非法引用是很困难和不切实际的。我们已经实现了非法引用检查,在调用`RuntimeApi.UnloadAssembly`
会打印出所有非法引用的日志。开发者根据打印的日志清除所有非法引用即可。

由于非法引用检查会遍历所有存活对象,比较耗时,因此只在Il2Cpp编译选项为Debug时开启了此检查,而Release模式下关闭了检查。可以使用
`RuntimeApi.EnableLiveObjectValidation(true)`强行在Release编译模式下开启这个检查。
由于非法引用检查会遍历所有存活对象,比较耗时,正式版本可以可以使用`RuntimeApi.EnableLiveObjectValidation(false)`禁用这个检查。

10 changes: 9 additions & 1 deletion docs/business/reload/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
调用 `RuntimeApi.UnloadAssembly` 卸载程序集,使用`Assembly.Load`重新加载程序集。当前不支持在未卸载该程序集的情况下再次加载该程序集,示例代码如下:

```csharp

// 卸载程序集时默认会扫描整个运行时,检查有没有持有对被卸载程序集中对象的引用。
// 对于正式发布的版本,可以使用以下语句禁用检查,缩短卸载时间。
// 开发期间强烈推荐不要禁用它
// RuntimeApi.EnableLiveObjectValidation(false);
// 第一次加载
Assembly ass = Assembly.Load(yyy);

Expand All @@ -44,4 +51,5 @@
- async或者协程很容易隐式地在其他线程保持了对卸载程序集代码的引用,卸载前请务必清理所有异步或者协程函数
- UI的OnClick或者各种回调事件很容易导致保持了对卸载程序集的引用,一定要清理干净
- 注册到全局的事件或者其他加高,容易意外保持了对卸载程序集的引用,一定要清理干净
- 根据`RuntimeApi.UnloadAssembly`中打印的非法引用的日志,清理掉代码中的非法引用
- 根据`RuntimeApi.UnloadAssembly`中打印的非法引用的日志,清理掉代码中的非法引用
- 正式发布的项目可以使用`RuntimeApi.EnableLiveObjectValidation(false)`禁用非法引用检查以缩短卸载耗时
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Hot reload technology requires that metadata of unloaded assembly U cannot be he

Real-world projects can be complex, and it is difficult and impractical for developers to find all illegal references. We have implemented illegal reference checks, and when calling `RuntimeApi.UnloadAssembly`, logs of all illegal references will be printed. Developers can clear all illegal references based on the printed logs.

Since illegal reference checks traverse all live objects, they are time-consuming. Therefore, this check is only enabled when the Il2Cpp compilation option is Debug, and it is disabled in Release mode. You can use `RuntimeApi.EnableLiveObjectValidation(true)` to forcibly enable this check in Release compilation mode.
Since illegal reference checks traverse all live objects, they are time-consuming. Therefore, You can use `RuntimeApi.EnableLiveObjectValidation(false)` to forcibly disable this check in Release mode.

0 comments on commit 594b8aa

Please sign in to comment.