summaryrefslogtreecommitdiffstats
path: root/src/com/android/calendar
diff options
context:
space:
mode:
authorPaul Sliwowski <psliwowski@google.com>2013-07-01 18:05:28 -0700
committerPaul Sliwowski <psliwowski@google.com>2013-07-01 18:05:28 -0700
commita8ad418a0552a03f40b1976b874044a99a5cba1c (patch)
treece1d2e0f9b1053370ce86bc61f3be532d1d810b4 /src/com/android/calendar
parent373e9dab4c22b74e0039427fd316544d93a5d318 (diff)
downloadandroid_packages_apps_Calendar-a8ad418a0552a03f40b1976b874044a99a5cba1c.tar.gz
android_packages_apps_Calendar-a8ad418a0552a03f40b1976b874044a99a5cba1c.tar.bz2
android_packages_apps_Calendar-a8ad418a0552a03f40b1976b874044a99a5cba1c.zip
Fix memory leak with CalendarController getInstance().
Bug: 9592810 Change-Id: If1b5fd470861fd0fdc63ca0c63ff2ea91b1b2c43
Diffstat (limited to 'src/com/android/calendar')
-rw-r--r--src/com/android/calendar/CalendarController.java14
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;
}