Finally understanding how references work in Android and Java
Enrique López Mañas
3.2K51

I’m trying to trigger a memory leak using you’r example, I created a gist here:https://gist.github.com/Rangor/ba014dae4bf97b287897d526902d5cbd

The activity consumes about 40MB of memory when it’s created. If I finish the activity and perform a manual GC the memory is freed. If i execute the AsyncTask (using a button that performs the asynctaskexecute method) and then finish the activity and perform a manual GC the memory is freed just the same. It also works without a manual GC as the OS will reclaim the 40MBs if it needs it inside the app.

Am I doing something wrong to create the memory leak or am I misunderstanding how the memory leak works?

Like what you read? Give Martin Syvertsen a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.