当你在操作图片或者其他大量文件数据时会出现:Failed to allocate a 38189038 byte allocation with 16777216 free bytes and 20MB until OOM 报错.

为什么会出现这个报错?原因很简单.因为一个app的内存只有64MB,而你在操作需要更多内存的文件.这个时候app无法申请到内存就会报这个错误.

解决办法

1.在清单文件中添加 android:largeHeap="true" 属性,将APP的内存从64MB拓展成128MB

<application
        android:name=".app.App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="demo"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:largeHeap="true"
        tools:replace="android:label">

2.尽量减少使用图片图标,用矢量图代替图标图片

3.尽快的释放一些不需要的使用的内存占用

4.保证app没有内存泄漏

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2021-12-24
  • 2021-06-29
  • 2022-12-23
猜你喜欢
  • 2021-05-08
  • 2022-12-23
  • 2022-02-04
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
相关资源
相似解决方案