欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

Android之java.lang.OutOfMemoryError: Failed to allocate a ** byte allocation with **free bytes and 2M

发布时间:2023/12/4 52 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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" <applicationandroid: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的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。