Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App is crashing on some devices. Android studio shows out of memory exception error

I am creating a music player app. I have three activities that have recycler views in it. I am loading music from server using exoplayer. I am loading like 10-20 images of 20kb size into recycler views using glide. My app is crashing in some phones with low memory. Android profiler shows that my app is consuming too much memory (screenshot below) App is running very smoothly in high-end phones. Can someone please tell me how to solve this memory issue so that app will run smoothly in all phones.

I have already added heaplarge=true in manifest

enter image description here

enter image description here

Android Studio Profiler

like image 982
Nabil Mohammed Nalakath Avatar asked Nov 08 '22 12:11

Nabil Mohammed Nalakath


2 Answers

add this in your build.gradle in android section

dexOptions {
        javaMaxHeapSize "4g" //specify the heap size for the dex process
    }

and add this in default config section

multiDexEnabled true

finally add dependency:

compile 'com.android.support:multidex:1.0.2'
like image 168
Tara Avatar answered Nov 14 '22 23:11

Tara


Maybe you have the Memory leak in your app.

  1. you can try to use leakCanary to help you find some Activity leak.

    link-to-github leakCanary

  2. Also you can use link to Analyze your code analyze

  3. try android StrictMode, it can help you improve your code Strict Mode

like image 29
nick zhou Avatar answered Nov 14 '22 22:11

nick zhou