为什么需要在TypedArray后调用recycle
2015-06-16 23:46
337 查看
转载自/article/4763116.html
当我们没有在使用TypedArray后调用recycle,编译器会提示“This TypedArray should be recycled after use with #recycle()”。
官方的解释是:回收TypedArray,以便后面重用。在调用这个函数后,你就不能再使用这个TypedArray。
在TypedArray后调用recycle主要是为了缓存。当recycle被调用后,这就说明这个对象从现在可以被重用了。
参考链接:
http://stackoverflow.com/questions/13805502/why-do-you-have-to-recycle-a-typedarray
http://developer.android.com/reference/android/content/res/TypedArray.html#recycle%28%29
当我们没有在使用TypedArray后调用recycle,编译器会提示“This TypedArray should be recycled after use with #recycle()”。
官方的解释是:回收TypedArray,以便后面重用。在调用这个函数后,你就不能再使用这个TypedArray。
在TypedArray后调用recycle主要是为了缓存。当recycle被调用后,这就说明这个对象从现在可以被重用了。
TypedArray内部持有部分数组,它们缓存在
Resources类中的静态字段中,这样就不用每次使用前都需要分配内存。你可以看看TypedArray.recycle()中的代码:
1 /** 2 * Give back a previously retrieved StyledAttributes, for later re-use. 3 */ 4 public void recycle() { 5 synchronized (mResources.mTmpValue) { 6 TypedArray cached = mResources.mCachedStyledAttributes; 7 if (cached == null || cached.mData.length < mData.length) { 8 mXml = null; 9 mResources.mCachedStyledAttributes = this; 10 } 11 } 12 }
参考链接:
http://stackoverflow.com/questions/13805502/why-do-you-have-to-recycle-a-typedarray
http://developer.android.com/reference/android/content/res/TypedArray.html#recycle%28%29
相关文章推荐
- java的匿名内部类
- Python变量
- H5版俄罗斯方块(1)---需求分析和目标创新
- [LeetCode] Combinations
- Map集合使用
- JSP deleteCategory.jsp (line: 9, column: 67) The JSP specification requires that an attribute name i
- Plus One
- php Hash函数了解
- vim方向键乱码
- 2015最流行的android组件、工具、框架大全
- javascript 获取调用属性的对象
- NodeJS框架express的途径映射(路由)功能及控制
- CentOS下如何完全卸载MySQL?解决卸载不干净的问题
- Android中如何查看内存
- 问题安装完hadoop后无法连接dfs
- Andriod网络优化相关技术点整理
- CentOS 7 之Helloworld with c
- ORA-01123:无法启动联机备份;未启用介质恢复.
- Struts2入门2
- Maven + Nexus + SVN + Eclipse 配置步骤说明