打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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更省内存。 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
android java.lang.OutOfMemoryError: bitmap size exceeds VM budget
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open
Matlab java.lang.OutOfMemoryError
如何解决java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion?
XE7 UP1编译Android Debug时报 “failed to allocate 190397160 bytes for output file: Not enough space”
resin 的 java.lang.OutOfMemoryError: PermGen space 解决办法。
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服