Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
实例清理最佳实践
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了在不再需要实例后清理实例的最佳实践。
在导航会话完成后使用 Navigator#clearDestinations 和 Navigator#cleanup
为防止内存泄漏并确保正确清理,请在导航会话完成后且不再需要 Navigator 实例时使用 Navigator#clearDestinations 和 Navigator#cleanup。当用户离开地图且调用关联 activity 的 onDestroy() 时,可以执行此操作。
在不再需要 GoogleMap 元素时清理它们
如果您的应用使用 GoogleMap 实例来提供非导航地图体验,请务必在不再需要该实例时将其清理掉。例如,通过分别调用 Polygon#remove、Polyline#remove 和 Marker#remove 方法,清理与 GoogleMap 关联的 Polygon、Polyline 和 Marker 元素。然后,在不再需要 GoogleMap 实例后,调用 GoogleMap#clear 将该实例分配给 null 以释放该实例。
如需详细了解如何在应用中使用 GoogleMap 实例,请参阅 GoogleMap 互动最佳实践。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-04-13。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2026-04-13。"],[],[]]