Tag Archives: java.lang.OutOfMemoryError: Failed to allocate a 146313228 byte allocation with 16777216 free bytes and 115MB until OOM

[Solved] Android Error: E/EGL_adreno: tid 3927: eglSurfaceAttrib(1334): error 0x3009 (EGL_BAD_MATCH)

1. Error Messages:

E/EGL_adreno: tid 3927: eglSurfaceAttrib(1334): error 0x3009 (EGL_BAD_MATCH)

java.lang.OutOfMemoryError: Failed to allocate a 146313228 byte allocation with 16777216 free bytes and 115MB until OOM

在这里插入图片描述

 

2. Reason

Description: The memory of our Android project is overflowing, my guess is that the reason may be the difference in resolution leading to memory overflow of the project content or too much content to load (images and other resources)
Especially controls that load a lot of data in a list have custom images.

 

3. Solution

Original Codes

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyFourth"
>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".service.MusicService"/>
</application>
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyFourth" > <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".service.MusicService"/> </application>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyFourth"
        >
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".service.MusicService"/>
    </application>

Add the following codes after <application:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
android:largeHeap="true"
android:hardwareAccelerated="false"
android:largeHeap="true" android:hardwareAccelerated="false"
android:largeHeap="true"
android:hardwareAccelerated="false"

Full Modified Codes

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyFourth"
android:largeHeap="true"
android:hardwareAccelerated="false"
>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".service.MusicService"/>
</application>
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyFourth" android:largeHeap="true" android:hardwareAccelerated="false" > <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".service.MusicService"/> </application>
<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyFourth"
        
        android:largeHeap="true"
        android:hardwareAccelerated="false"

        >
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".service.MusicService"/>
    </application>
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
android:hardwareAccelerated="true"
android:hardwareAccelerated="true"
android:hardwareAccelerated="true"

An application that uses largeHeap will request the system to allocate more memory space for the Dalvik virtual machine. It is also easy to use, just add android:largeHeap=”true” to the application node of the manifest file.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
android:hardwareAccelerated="false"
android:hardwareAccelerated="false"
android:hardwareAccelerated="false" 

The default is true which will start hardware acceleration but will, however, take up memory