zoukankan      html  css  js  c++  java
  • Android开发 处理内存申请失败的报错(Failed to allocate a 38189038 byte allocation with 16777216 free bytes and 20MB until OOM)

    问题原因

      当你在操作图片或者其他大量文件数据时会出现: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没有内存泄漏

  • 相关阅读:
    CF919F A Game With Numbers
    CF1005F Berland and the Shortest Paths
    CF915F Imbalance Value of a Tree
    CF1027F Session in BSU
    CF1029E Tree with Small Distances
    CF1037E Trips
    CF508E Arthur and Brackets
    CF1042F Leaf Sets
    [HNOI2012]永无乡
    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/11169137.html
Copyright © 2011-2022 走看看