diff options
author | Paul Sliwowski <psliwowski@google.com> | 2013-07-02 18:36:08 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-07-02 18:36:08 -0700 |
commit | 6e2e8b36e0b61bfaee4efa192835a46b0f4a9f55 (patch) | |
tree | ce1d2e0f9b1053370ce86bc61f3be532d1d810b4 | |
parent | 99bb396dbad924c3780226cac10542ebfce9ff37 (diff) | |
parent | a8ad418a0552a03f40b1976b874044a99a5cba1c (diff) | |
download | android_packages_apps_Calendar-6e2e8b36e0b61bfaee4efa192835a46b0f4a9f55.tar.gz android_packages_apps_Calendar-6e2e8b36e0b61bfaee4efa192835a46b0f4a9f55.tar.bz2 android_packages_apps_Calendar-6e2e8b36e0b61bfaee4efa192835a46b0f4a9f55.zip |
am a8ad418a: Fix memory leak with CalendarController getInstance().
* commit 'a8ad418a0552a03f40b1976b874044a99a5cba1c':
Fix memory leak with CalendarController getInstance().
-rw-r--r-- | src/com/android/calendar/CalendarController.java | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/com/android/calendar/CalendarController.java b/src/com/android/calendar/CalendarController.java index 15733715..93b1b489 100644 --- a/src/com/android/calendar/CalendarController.java +++ b/src/com/android/calendar/CalendarController.java @@ -43,6 +43,7 @@ import android.util.Pair; import com.android.calendar.event.EditEventActivity; import com.android.calendar.selectcalendars.SelectVisibleCalendarsActivity; +import java.lang.ref.WeakReference; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -74,8 +75,8 @@ public class CalendarController { private Pair<Integer, EventHandler> mToBeAddedFirstEventHandler; private volatile int mDispatchInProgressCounter = 0; - private static WeakHashMap<Context, CalendarController> instances = - new WeakHashMap<Context, CalendarController>(); + private static WeakHashMap<Context, WeakReference<CalendarController>> instances = + new WeakHashMap<Context, WeakReference<CalendarController>>(); private final WeakHashMap<Object, Long> filters = new WeakHashMap<Object, Long>(1); @@ -281,10 +282,15 @@ public class CalendarController { */ public static CalendarController getInstance(Context context) { synchronized (instances) { - CalendarController controller = instances.get(context); + CalendarController controller = null; + WeakReference<CalendarController> weakController = instances.get(context); + if (weakController != null) { + controller = weakController.get(); + } + if (controller == null) { controller = new CalendarController(context); - instances.put(context, controller); + instances.put(context, new WeakReference(controller)); } return controller; } |