'Android Studio memory profiler have some serious memory issues

I am trying to fix some memory leaks in my apps but I am always fighting with memory profiler instability itself instead of being able to focus on my task. Interestingly few people report this so here I am. My project is huge but I already increased recommended Android Studio memory values. I just want to capture Heap Dump, because recording is totally unstable obviously and even more system memory is necessary, but even with just heap dump capture when I am jumping between various captures my android studio gets to the point I have to kill it start again what really slows me down. Its really killing my productivity, to find memory leaks is hard task but without working tool its super hard. I have MacBook Air M1 8 GB ram that is really snappy but now I believe I seriously need better machine with more memory or something is seriously wrong here.

I am running Android Studio Bumble Bee 2021.1.1 Patch 2

I am getting mostly this:

enter image description here

Until in hangs totally.

My memory settings are like this now:

2048 Max Heap Size, Gradle 2048, Kotlin 1024.

The problem is I even cannot increase Max Heap Size in Settings so probably I have to alter some configuration directly.

My question is what memory increase is really necessary so I can do simple heap dump without getting unresponsive android Studio how to change it or whatever tip to be able to capture heap dump of my app running in emulator while being able to browse it with search to look for instances, maybe som other tool ?. My desire is also to not allocate unnecessary ram so I can still run multiple apps and emulators at once if necessary.

Any help appreciated.



Solution 1:[1]

Looks like when setting debuggable false temporarily for your build you want to profile you get less memory issues.

...
buildTypes {
        debug {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }...

Also there is some trick like

<profileable
    android:shell="true"
    tools:targetApi="q" />

That is documented here https://developer.android.com/studio/profile. My first solution was to use this profileable together with changing debuggable to false for debug buildType in build.gradle. Then I found out that I just have to use not debuggable build for profile to have less memory footprint and then... when I updated Android Studio, as is usual for us developers, problems with IDE magically disappeared, for now.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Renetik