Skip to content Skip to sidebar Skip to footer

What's Exactly A Memory Leak In This Case?

To clear all background activities I did the following: I kept a static array list, and whenever I used to go from one activity to another, in the onCreate() method of new activity

Solution 1:

Holding references to activities outside their context (when they are in background or "closed"/finished) causes memory to leak - the Android operating system would like to clear from memory "old" activities when it decides it's the time to do so (You can't control it manually).

In that case - the garbage collector would try to free the activity / activities from memory, but because something (your array of references to activities) is holding a reference to it - it can't be garbage collected, so it can't free it from memory- and that's a sample of a memory leak.

This document describes how to avoid memory leaks:

http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html

Solution 2:

Try rotating the device a couple of times and see what happens- you'll eventually run out of memory because you're still holding a reference to previous contexts which the GC can't clear.

Post a Comment for "What's Exactly A Memory Leak In This Case?"