我创建了一个GalleryView
和ImageView
,当在图库中点击一个项目时,它会显示更大的图像。我使用以下代码实现了ImageAdapter
:
public ImageAdapter(Context c)
{
context = c;
TypedArray a = obtainStyledAttributes(R.styleable.gallery1);
itemBackground = a.getResourceId(R.styleable.gallery1_android_galleryItemBackground, 0);
a.recycle();
}
当我删除语句a.recycle()
时,没有变化,应用程序运行正常,但是我读到的每个地方都说必须回收typedArray
。如果我的应用程序运行方式没有改变,那么recycle()
方法有什么用处?
TypedArray
相关联的内存可以被稍后的调用者(而不是程序内部你所理解的实例本身)重新使用。这就是为什么文档还说“调用此函数后,您绝不能再次触摸类型化数组。”。 - Vinay