android笔记2——关于图片缓存的一些注意事项

当应用页面需要网络加载很多图片的时候,为了提高效率,需要缓存图片,前段时间写了一个需要加载很多网络图片的ListView页面,当时为了提高效率将下载的图片用一个软引用字段进行缓存,但是效果不尽人意,缓存的图片被回收的很快,基本达不到效果,后面看见官方文档有这样一句话“In the past, a popular memory cache implementation was aSoftReference or WeakReference bitmap cache, however this is notrecommended. Starting from Android 2.3 (API Level 9) the garbage collector ismore aggressive with collecting soft/weak references which makes them fairlyineffective. In addition, prior to Android 3.0 (API Level 11), the backing dataof a bitmap was stored in native memory which is not released in a predictablemanner, potentially causing an application to briefly exceed its memory limitsand crash.”大概意思就是:从Android2.3以后,GC机制将变得更加频繁,软/弱引用的效率低了很多,而在3.0以前,bitmap是存放在native内存中,是不可预知的被释放,可能会导致崩溃。因此bitmap缓存不能直接使用软引用,需要借助类似如LruCache内部使用强引用进行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值