Java – How to find the root cause of a memory leak?

How to find the root cause of a memory leak?… here is a solution to the problem.

How to find the root cause of a memory leak?

My app is basically an image editor. There is a welcome page that opens the main activity with intents. If the direction of the primary activity runtime changes, the memory consumption only doubles and remains that way. If I close the main activity and go back to the Welcome activity and start the main activity again, the same issue does not occur. I think all of this indicates a memory leak, I’ve investigated myself but can’t find the cause of the app leaking memory. I’m using an application context and I don’t have static fields in my app. I tried dumping the heap and analyzing it using MAT, but I couldn’t find anything good. I hope someone can tell me in the right direction, find the source of the memory leak or other possible explanation of the problem.

Solution

This specific scenario is covered in the Google I|O 2011 conference presentation. I recommend watching the presentation because it helps you better find problems using MATT.

Related Problems and Solutions