gpt4 book ai didi

android - 如何找到特定的可绘制对象具有上下文的引用

转载 作者:太空狗 更新时间:2023-10-29 13:25:29 25 4
gpt4 key购买 nike

现在我正在阅读 Roman's Guy 教程 Avoid memory leak ,有下面这句话:

Drawable is attached to a view, the view is set as a callback on the drawable. In the code snippet above, this means the drawable has a reference to the TextView` , Text in webpage .

如何判断 drawable 是否有对 Context 的引用?

最佳答案

在这种情况下,问题是可绘制实例静态存储在一个类中(因此它永远不会被垃圾回收)并且它保留对 Activity 的引用,这意味着该 Activity 也不会被垃圾回收(即使它已终止)。因此内存泄漏。

在您的调试器中,您可以检查可绘制实例并查看是否有任何字段引用另一个 View /上下文。

但只要避免静态存储 UI 内容,它就会解决很多类似的问题:)

关于android - 如何找到特定的可绘制对象具有上下文的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21694527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com