diff options
author | Jeff Brown <jeffbrown@google.com> | 2010-06-02 15:35:46 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2010-06-02 15:36:01 -0700 |
commit | d28f4be870ea8850a2d4a2fe51333643f16b9ab1 (patch) | |
tree | 3275e1bdf086968c859567e90a2373b1b424a7b4 | |
parent | 501b2b400a15a43849ff84c5da4e68d23ed726cf (diff) | |
download | frameworks_base-d28f4be870ea8850a2d4a2fe51333643f16b9ab1.zip frameworks_base-d28f4be870ea8850a2d4a2fe51333643f16b9ab1.tar.gz frameworks_base-d28f4be870ea8850a2d4a2fe51333643f16b9ab1.tar.bz2 |
Fixed some minor bugs in MotionEvent recycling.
1. MotionEvent.recycle() never set mRecycled to true so it couldn't actually
detect doubly-recycled events (unless the TRACK_RECYCLED_LOCATION debuging
flag was enabled).
2. MotionEvent.obtain() did not set mNext to null before returning the event
so it would unnecessarily retain a reference to other events in the
recycled event linked list until recycled again.
Change-Id: I93709c402d260691875f632dfc080a355f85fbb0
-rw-r--r-- | core/java/android/view/MotionEvent.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index d648e96..eefbf7a 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -255,17 +255,19 @@ public final class MotionEvent implements Parcelable { } static private MotionEvent obtain() { + final MotionEvent ev; synchronized (gRecyclerLock) { if (gRecyclerTop == null) { return new MotionEvent(); } - MotionEvent ev = gRecyclerTop; + ev = gRecyclerTop; gRecyclerTop = ev.mNext; gRecyclerUsed--; - ev.mRecycledLocation = null; - ev.mRecycled = false; - return ev; } + ev.mRecycledLocation = null; + ev.mRecycled = false; + ev.mNext = null; + return ev; } /** @@ -620,11 +622,14 @@ public final class MotionEvent implements Parcelable { throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation); } mRecycledLocation = new RuntimeException("Last recycled here"); - } else if (mRecycled) { - throw new RuntimeException(toString() + " recycled twice!"); + //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation); + } else { + if (mRecycled) { + throw new RuntimeException(toString() + " recycled twice!"); + } + mRecycled = true; } - //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation); synchronized (gRecyclerLock) { if (gRecyclerUsed < MAX_RECYCLED) { gRecyclerUsed++; |