OSDN Git Service

Fix memory leaks in music app.
authorMarco Nelissen <marcone@google.com>
Thu, 13 Aug 2009 16:58:43 +0000 (09:58 -0700)
committerMarco Nelissen <marcone@google.com>
Thu, 13 Aug 2009 17:14:34 +0000 (10:14 -0700)
Fixes http://b/issue?id=2046569

src/com/android/music/AlbumBrowserActivity.java
src/com/android/music/ArtistAlbumBrowserActivity.java
src/com/android/music/PlaylistBrowserActivity.java
src/com/android/music/QueryBrowserActivity.java
src/com/android/music/TrackBrowserActivity.java

index 0d6c150..6f326a0 100644 (file)
@@ -150,6 +150,11 @@ public class AlbumBrowserActivity extends ListActivity
                 c.close();
             }
         }
+        // Because we pass the adapter to the next activity, we need to make
+        // sure it doesn't keep a reference to this activity. We can do this
+        // by clearing its DatasetObservers, which setListAdapter(null) does.
+        setListAdapter(null);
+        mAdapter = null;
         unregisterReceiver(mScanListener);
         super.onDestroy();
     }
index 35bf54e..0932f12 100644 (file)
@@ -158,6 +158,11 @@ public class ArtistAlbumBrowserActivity extends ExpandableListActivity
                 c.close();
             }
         }
+        // Because we pass the adapter to the next activity, we need to make
+        // sure it doesn't keep a reference to this activity. We can do this
+        // by clearing its DatasetObservers, which setListAdapter(null) does.
+        setListAdapter(null);
+        mAdapter = null;
         unregisterReceiver(mScanListener);
         super.onDestroy();
     }
index da934b2..df2b138 100644 (file)
@@ -175,6 +175,11 @@ public class PlaylistBrowserActivity extends ListActivity
                 c.close();
             }
         }        
+        // Because we pass the adapter to the next activity, we need to make
+        // sure it doesn't keep a reference to this activity. We can do this
+        // by clearing its DatasetObservers, which setListAdapter(null) does.
+        setListAdapter(null);
+        mAdapter = null;
         unregisterReceiver(mScanListener);
         super.onDestroy();
     }
index a67790a..b0e8dac 100644 (file)
@@ -181,6 +181,11 @@ implements MusicUtils.Defs, ServiceConnection
                 c.close();
             }
         }
+        // Because we pass the adapter to the next activity, we need to make
+        // sure it doesn't keep a reference to this activity. We can do this
+        // by clearing its DatasetObservers, which setListAdapter(null) does.
+        setListAdapter(null);
+        mAdapter = null;
     }
     
     /*
index 1f1adf6..14764ff 100644 (file)
@@ -240,6 +240,11 @@ public class TrackBrowserActivity extends ListActivity
                 c.close();
             }
         }
+        // Because we pass the adapter to the next activity, we need to make
+        // sure it doesn't keep a reference to this activity. We can do this
+        // by clearing its DatasetObservers, which setListAdapter(null) does.
+        setListAdapter(null);
+        mAdapter = null;
         unregisterReceiverSafe(mScanListener);
         super.onDestroy();
     }