上游 · Kotlin/Native binary options
appStateTracking:Controls timer-based invocation of the garbage collector when the application runs in the background. When enabled, GC is called only when memory consumption becomes too high.
全部配置 / KN-BINARY-APPSTATETRACKING
Xbinary=appStateTracking · KN-BINARY-APPSTATETRACKING · 编译器参数(Native)
默认值:未设置。未指定时由消费侧决定;未核对前不写死取值。使用场合:场景可配。场景可配:有明确目标(性能、包体、安全、兼容)时再改。
用途。启用应用前后台状态跟踪。示例取值:`appStateTracking=enabled`(后台抑制定时 GC)。官方说明:Controls timer-based invocation of the garbage collector when the application runs in the background. When enabled, GC is called only when memory consumption becomes too high.
影响。改变 Native 产物布局、运行时或导出行为;默认保持关闭更稳妥。
适用场景。场景可配。有明确需求再改,无需求时保持发行版默认更稳妥。改前核对目标限制与联动项,改后做冒烟。
| 可写取值 | 含义 | 使用场景 |
|---|---|---|
disabled | 关闭应用状态跟踪(文档默认) | 默认;或排查状态跟踪相关问题时关闭 |
enabled | 允许按应用状态跟踪,影响后台 GC 触发策略 | 后台时希望仅在内存过高才触发 GC(见上游说明) |
含义/场景依据:upstream native-binary-options(appStateTracking)
定义依据:konan/BinaryOptions.kt 在仓库中打开; konan/AppStateTracking.kt 在仓库中打开
// 文件:build.gradle.kts(应用的 Kotlin 模块,例如 composeApp)
kotlin {
ohosArm64 { // 按实际 native target 调整
binaries.all {
freeCompilerArgs += "-Xbinary=appStateTracking=enabled" // 后台抑制定时 GC
}
}
}
不写这个配置时,编译器会怎么处理?
此选项默认未设置(空列表 / 空映射 / null)。不设置时由其他逻辑决定行为或直接跳过。
未指定时由消费侧决定;未核对前不写死取值。
以下摘抄原文中与本配置最相关的段落,便于速读;完整上下文请点原文。
appStateTracking:Controls timer-based invocation of the garbage collector when the application runs in the background. When enabled, GC is called only when memory consumption becomes too high.