引入largeHeap屬性
禁用Glide內存緩存
自定義GlideModule
asDrawable代替asBitmap
imageView的scaleType屬性
是否使用全局變量
引入largeHeap屬性
讓系統爲App分配更多的獨立內存。
<application
android:largeHeap="true">
</application>
禁用Glide內存緩存
Glide.with(this)
.load("")
.skipMemoryCache(true)//禁用內存緩存
.into();
自定義GlideModule
設置MemoryCache和BitmapPool大小
在另一篇文章有寫怎麼配置:Glide簡單使用
asDrawable代替asBitmap
級到Glide4.0,asDrawable代替asBitmap,drawable更省內存
Glide.with(this)
.asDrawable()
.load("")
.into(img);
imageView的scaleType屬性
ImageView的scaleType爲fitXY時,改爲fitCenter/centerCrop/fitStart/fitEnd顯示。
是否使用全局變量
- 不使用application作爲context。當context爲application時,會把imageView是生命週期延長到整個運行過程中,imageView不能被回收,從而造成OOM異常
- 使用application作爲context。但是對ImageView使用弱引用或軟引用,儘量使用SoftReference,當內存不足時,將及時回收無用的ImageView。