當(dāng)前位置:
首頁(yè) >
Android之java.lang.OutOfMemoryError: Failed to allocate a ** byte allocation with **free bytes and 2M
發(fā)布時(shí)間:2023/12/4
45
豆豆
生活随笔
收集整理的這篇文章主要介紹了
Android之java.lang.OutOfMemoryError: Failed to allocate a ** byte allocation with **free bytes and 2M
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1 問題
glide加載圖片出現(xiàn)oom
java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM?
?
?
?
?
?
?
?
?
2 解決辦法
1) 簡(jiǎn)單粗暴點(diǎn)的在AndroidManifest.xml添加如下,增大安卓虛擬機(jī)內(nèi)存
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里面設(shè)置禁止內(nèi)存緩存和使用磁盤緩存
public static final RequestOptions requestOptions = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL).skipMemoryCache(true);然后使用asDrawable代替asBitmap,drawable更省內(nèi)存。?
?
總結(jié)
以上是生活随笔為你收集整理的Android之java.lang.OutOfMemoryError: Failed to allocate a ** byte allocation with **free bytes and 2M的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android之实现RTL的ViewPa
- 下一篇: Android之Only fullscr