Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM

前端 未结 30 2140
暗喜
暗喜 2020-11-21 07:33

I want to show the Bitmap image in ImageView from sd card which is stored already. After run my application is crash and getting Ou

相关标签:
30条回答
  • 2020-11-21 07:49

    Use Glide Library and Override size to less size;

    Glide.with(mContext).load(imgID).asBitmap().override(1080, 600).into(mImageView);
    
    0 讨论(0)
  • 2020-11-21 07:49

    In some cases (e.g. operations in a loop) garbage collector is slower than your code. You can use a helper method from this answer to wait for garbage collector.

    0 讨论(0)
  • 2020-11-21 07:52

    This worked for me: just move images from drawable folder to drawable-hdpi.

    0 讨论(0)
  • 2020-11-21 07:53

    For me, the problem was that my .png file was being de-compressed to be a really huge bitmap in memory, because the image had very large dimensions (even though the file size was tiny).

    So the fix was to simply resize the image :)

    0 讨论(0)
  • 2020-11-21 07:53

    Issue : Failed to allocate a 37748748 byte allocation with 16777120 free bytes and 17MB until OOM

    Solution : 1.open your manifest file 2. inside application tag just add below two lines

     android:hardwareAccelerated="false"
     android:largeHeap="true"
    

    Example :

     <application
            android:allowBackup="true"
            android:hardwareAccelerated="false"
            android:largeHeap="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
    
    0 讨论(0)
  • 2020-11-21 07:53

    add this to your manifest under applications? android:largeHeap="true"

    0 讨论(0)
提交回复
热议问题