From 06e52f8e8c86f7f79ac03717a62b5c76d3ad8ad5 Mon Sep 17 00:00:00 2001 From: Adam Comella Date: Wed, 31 Aug 2016 07:20:30 -0700 Subject: [PATCH] Fix bug in timer clean up Summary: One of the impacts of this bug is that Java is firing timer completion events into JavaScript for timers that should have been deleted. JavaScript filters these out so it doesn't impact the app developer. However, Java is completing more timers than necessary. When cleaning up a timer, we were accidentally deleting the whole set of timers for that context. Instead, we should just delete that timer from its context. Adam Comella Microsoft Corp. Closes https://github.com/facebook/react-native/pull/9361 Differential Revision: D3797573 fbshipit-source-id: c30ed600af741601f2babdfc61da9aac549cbadb --- .../com/facebook/react/modules/core/Timing.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java index 2fc348e8d5c..bcf62557321 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java @@ -104,7 +104,13 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl timer.mTargetTime = frameTimeMillis + timer.mInterval; mTimers.add(timer); } else { - mTimerIdsToTimers.remove(timer.mExecutorToken); + SparseArray timers = mTimerIdsToTimers.get(timer.mExecutorToken); + if (timers != null) { + timers.remove(timer.mCallbackID); + if (timers.size() == 0) { + mTimerIdsToTimers.remove(timer.mExecutorToken); + } + } } } } @@ -385,7 +391,10 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl return; } // We may have already called/removed it - mTimerIdsToTimers.remove(executorToken); + timersForContext.remove(timerId); + if (timersForContext.size() == 0) { + mTimerIdsToTimers.remove(executorToken); + } mTimers.remove(timer); } }