在视图中声明内部类危险吗?

发布于 01-07 10:06 字数 107 浏览 3 评论 0原文

我读过Android官方技术文章:“如何避免内存泄漏?”。他们说在 Activity 类中创建内部类很危险,但是在 View 类中创建内部类又如何:泄漏危险是相同还是更严重?

I've read the official Android technical article: "how to avoid memory leaks ?". They say that creating inner classes in an Activity class is dangerous, but what about creating inner class inside a View class : is the leak danger the same or worse ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記憶穿過時間隧道2025-01-14 10:06:48

如果您创建的类的生命周期不超过视图,那就没问题。否则你应该避免这样做。

如果您使用这种结构 - 当不需要视图时,请确保您没有内部类实例上的任何链接。然后GC会收集所有东西,并且不会出现内存泄漏。

If you create classes with lifecycle not more than view - it's OK. Otherwise you should avoid doing this.

If you use such structure - be sure, that you do not have any links on instances of inner class, when view is not necessary. Then GC will collect everything, and there will not memory leaks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文