android对象池
来源:互联网 发布:美国cpi数据公布时间 编辑:程序博客网 时间:2024/06/05 14:59
对象池出现主要是用于避免内存抖动。
android-supportv4中提供了Pools的类实现了对象池。
对象池使用的基本思路是:将用过的对象保存起来,等下一次需要这种对象的时候,再拿出来重复使用,从而在一定程度上减少频繁创建对象所造成的开销。 并非所有对象都适合拿来池化――因为维护对象池也要造成一定开销。对生成时开销不大的对象进行池化,反而可能会出现“维护对象池的开销”大于“生成新对象的开销”,从而使性能降低的情况。但是对于生成时开销可观的对象,池化技术就是提高性能的有效策略了。
Pools是基于数组的实现的。使用方法:
public class MyPooledClass {
private static final SynchronizedPool<MyPooledClass> sPool =
new SynchronizedPool<MyPooledClass>(10);
public static MyPooledClass obtain() {
MyPooledClass instance = sPool.acquire();
return (instance != null) ? instance : new MyPooledClass();
}
public void recycle() {
// Clear state if needed.
sPool.release(this);
}
. . .
}
Message也用到了对象池,它是基于链表的。
- android对象池
- Android对象池
- android 线程池对象-ThreadPoolExecutor
- android 线程池对象-ThreadPoolExecutor
- android 线程池对象-ThreadPoolExecutor
- android 线程池对象-ThreadPoolExecutor
- android对象池之Message
- Android 对象
- Android中对象池的使用
- Android 性能优化对象池技术 <5>
- Android中对象池的使用
- android中使用对象池 ----- Pools
- [Android]一个简单的对象池
- Android 添加窗口对象
- Android对象传值
- Android传递对象
- android 之对象传递
- Android图片对象转换
- 《流金时代》有感
- HDU 1848 Fibonacci again and again(学习sg函数后写出来的第一个题)
- Spark算子:RDD基本转换操作(6)–zip、zipPartitions
- Android报No resource found that matches the given name问题的解决
- c语言结构体记录2--按数据块读入读出
- android对象池
- 正态分布R语言实例
- Palisade.DecisionTools.Suite.7.0.Win
- linux0.11版内核的mktime分析
- 【工具安装】-CentOS-安装python包管理工具pip
- Android自学笔记(一)Android系统架构
- Spark算子:RDD键值转换操作(1)–partitionBy、mapValues、flatMapValues
- 英语学习
- 张尔摩斯集