网络上有很多解决的办法,但是都是在清理磁盘缓存和内存上做,并不能及时释放内存。
1.可以在每次请求数据和加载数据后调用
/** * 清除内存缓存. */
public static void clearMemoryCache(Context context){
// This method must be called on the main thread.
System.gc();
// Glide.get(context).clearMemory();
GlideApp.get(context).clearMemory();
}
/** * 清除磁盘缓存.必须在子线程里做 */
public static void clearDiskCache(Context context){
System.gc();
new AsyncTask(){
@Override protected Void doInBackground(Void... params) {
// This method must be called on a background thread.
GlideApp.get(context).clearMemory();
// Glide.get(context).clearDiskCache(); return null; }
};
}
2.可以设置磁盘缓存的大小
@GlideModule
public final class MyGlideModule extends AppGlideModule {
/** * MemorySizeCalculator类通过考虑设备给
最后
以上就是仁爱花生最近收集整理的关于android glide内存溢出,在Recyclerview使用GlideAPP加载大量图片导致内存溢出(oom)的全部内容,更多相关android内容请搜索靠谱客的其他文章。
发表评论 取消回复