我是靠谱客的博主 玩命超短裙,最近开发中收集的这篇文章主要介绍Android之java.lang.OutOfMemoryError: Failed to allocate a ** byte allocation with **free bytes and 2M,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1 问题

glide加载图片出现oom

java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM

 

 

 

 

 

 

 

 

 

2 解决办法

1) 简单粗暴点的在AndroidManifest.xml添加如下,增大安卓虚拟机内存

android:largeHeap="true"
<application
    android:allowBackup="true"
    android:icon="@mipmap/guruji"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:largeHeap="true"
    android:theme="@style/AppTheme">

2)在glide里面设置禁止内存缓存和使用磁盘缓存

public static final RequestOptions requestOptions = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL).skipMemoryCache(true);

然后使用asDrawable代替asBitmap,drawable更省内存。 

 

最后

以上就是玩命超短裙为你收集整理的Android之java.lang.OutOfMemoryError: Failed to allocate a ** byte allocation with **free bytes and 2M的全部内容,希望文章能够帮你解决Android之java.lang.OutOfMemoryError: Failed to allocate a ** byte allocation with **free bytes and 2M所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部