Memory leak: using non static inner class

Put your problem here if it does not fit any of the other categories.

Memory leak: using non static inner class

Postby ninovanhooff » Sat Mar 24, 2012 6:14 pm

I suspect to have a memory leak in my "NamesListActivity"

When using MAT (memory analyser tool), I see two instances of this activity after rotating the screen a few times. I expect there to be one. As a result, lots of members are present twice as well
One of the causes could be non-static inner classes. Ive got two of those:
-IconicAdapter: a custom listview adapter, stored in a variable private to NamesListActivity,
- backReceiver: a receiver for when the back button is pressed. It is also held in a private field. It is registered in onResume and unRegistered in onPause

heap size: 9mb when activity has not been started, after rotating the screen a few times it stabilizes at 25-30mb.
The background image should be 11mb in size, so that's not dramatic.
There is a big difference. In running mode. The above happens in normal run mode (play button in eclipse)
When in debug mode, heap size increases on every screen rotation by 6 or 11 mb. Eventually this results in force close.

Do I even have a memory leak, and why are there exactly two instances of my activity? pretty sure it's started once.


Code: Select all
public class NamesListActivity extends ListActivity {
   private IconicAdapter adapter=null;
   private ArrayList<String> array=new ArrayList<String>();
   private boolean[] nameIsSelected;
   private static final String TAG = "baby";
   public static final String EDIT_TAG = "EDIT";
   private int edit_pos = -1;
   private View edit_view;
   public static Typeface tf;
   TouchListView tlv;
   public static View footer;
   //private TouchListView tlv=(TouchListView)getTouchListView();
   //action ID's
   public static final int DELETE_ID=0;
   public static final int EDIT_ID=1;
   public static final int CLEAR_ID=2; // clear list
   public static final int COPY_ID=3;
   private String OWNER_NAME = LOCAL_USER;//TODO was initialized to -1
   private String SEX = "M";
   private int LIST_ROW_ID;
   private NamesDbAdapter mDbHelper;
   //private Cursor cursor;
   public Context context;
   private int resultcode = 0;
   private BroadcastReceiver receiver;
   static SharedPreferences prefs;
   OnClickListener footer_listener = new OnClickListener() {
Once Poster
Once Poster
Posts: 1
Joined: Sat Mar 24, 2012 5:54 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 3 guests