【发布时间】:2016-02-02 01:45:19
【问题描述】:
来自https://developer.android.com/training/improving-layouts/smooth-scrolling.html#ViewHolder
> A ViewHolder object stores each of the component views inside the
> tag field of the Layout, so you can immediately access them without
> the need to look them up repeatedly.
在 android 中更改方向后,将重新创建列表视图,因此所有列表视图项目 丢失了。
例子:
/** ViewHolder attached to ListView-Item.tag */
public static class MyViewHolder {
/** the image belonging to ListView-Item */
ImageView mListViewItemImage;
}
我的问题:这是否会导致内存泄漏,因为存在循环引用:
- ListView-Item.tag 引用 MyViewHolder
- MyViewHolder.mListViewItemImage 引用了在方向更改后丢弃的旧 gui。
如果这导致内存泄漏,我是否必须实现 ViewHolder 垃圾回收?
【问题讨论】:
标签: android listview memory-leaks android-orientation