From 594b8aac8d265254e509916065b84b687872a0bb Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 24 May 2024 17:33:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0hotreload=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E5=85=B3=E4=BA=8E=20RuntimeApi.EnableLiveObjectValidation?= =?UTF-8?q?=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/business/reload/hotreloadassembly.md | 3 +-- docs/business/reload/quickstart.md | 10 +++++++++- .../current/business/reload/hotreloadassembly.md | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/business/reload/hotreloadassembly.md b/docs/business/reload/hotreloadassembly.md index b0215db7..40033555 100644 --- a/docs/business/reload/hotreloadassembly.md +++ b/docs/business/reload/hotreloadassembly.md @@ -40,6 +40,5 @@ 实际工程可能很复杂,开发者找出所有非法引用是很困难和不切实际的。我们已经实现了非法引用检查,在调用`RuntimeApi.UnloadAssembly`时 会打印出所有非法引用的日志。开发者根据打印的日志清除所有非法引用即可。 -由于非法引用检查会遍历所有存活对象,比较耗时,因此只在Il2Cpp编译选项为Debug时开启了此检查,而Release模式下关闭了检查。可以使用 -`RuntimeApi.EnableLiveObjectValidation(true)`强行在Release编译模式下开启这个检查。 +由于非法引用检查会遍历所有存活对象,比较耗时,正式版本可以可以使用`RuntimeApi.EnableLiveObjectValidation(false)`禁用这个检查。 diff --git a/docs/business/reload/quickstart.md b/docs/business/reload/quickstart.md index 3d642777..0668c4a8 100644 --- a/docs/business/reload/quickstart.md +++ b/docs/business/reload/quickstart.md @@ -18,6 +18,13 @@ 调用 `RuntimeApi.UnloadAssembly` 卸载程序集,使用`Assembly.Load`重新加载程序集。当前不支持在未卸载该程序集的情况下再次加载该程序集,示例代码如下: ```csharp + + // 卸载程序集时默认会扫描整个运行时,检查有没有持有对被卸载程序集中对象的引用。 + // 对于正式发布的版本,可以使用以下语句禁用检查,缩短卸载时间。 + // 开发期间强烈推荐不要禁用它 + + // RuntimeApi.EnableLiveObjectValidation(false); + // 第一次加载 Assembly ass = Assembly.Load(yyy); @@ -44,4 +51,5 @@ - async或者协程很容易隐式地在其他线程保持了对卸载程序集代码的引用,卸载前请务必清理所有异步或者协程函数 - UI的OnClick或者各种回调事件很容易导致保持了对卸载程序集的引用,一定要清理干净 - 注册到全局的事件或者其他加高,容易意外保持了对卸载程序集的引用,一定要清理干净 -- 根据`RuntimeApi.UnloadAssembly`中打印的非法引用的日志,清理掉代码中的非法引用 \ No newline at end of file +- 根据`RuntimeApi.UnloadAssembly`中打印的非法引用的日志,清理掉代码中的非法引用 +- 正式发布的项目可以使用`RuntimeApi.EnableLiveObjectValidation(false)`禁用非法引用检查以缩短卸载耗时 \ No newline at end of file diff --git a/i18n/en/docusaurus-plugin-content-docs/current/business/reload/hotreloadassembly.md b/i18n/en/docusaurus-plugin-content-docs/current/business/reload/hotreloadassembly.md index 44664064..704ae8e8 100644 --- a/i18n/en/docusaurus-plugin-content-docs/current/business/reload/hotreloadassembly.md +++ b/i18n/en/docusaurus-plugin-content-docs/current/business/reload/hotreloadassembly.md @@ -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.