Recently I tried Android Studio It seems my app is not working and after a while stops working! Here is the profiler screenshot
My question is, How to detect the memory leak? As I press the dump head memory app stops from running.
Are the sharp edges represents the memory leak?
Are the sharp edges represnts the memory leak?
No. It's the other way around. The sharp edges you see result from the garbage collector reclaiming memory from your app. With a memory leak, your app's memory usage would increase over time.
However, it seems your app is creating lots of objects. This is normal as long as your app actually does something useful (i.e. not just sitting there waiting for user input).
There are different methods for checking Memory Leak in Android
One of most famous is LeakCanary by square
A memory leak detection library for Android and Java.
“A small leak will sink a great ship.” - Benjamin Franklin
In your build.gradle:
dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.2'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.2'
}
In your Application class:
public class ExampleApplication extends Application {
@Override public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);
// Normal app init code...
}
}
In your Manifest.xml
<application
android:name=".ExampleApplication"
...
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With