From 144524f103ae4d8f1225924875395d55fa1db8a6 Mon Sep 17 00:00:00 2001 From: iPel Date: Wed, 19 Apr 2023 20:56:06 +0800 Subject: [PATCH] fix(android): memory leak of `RecyclerViewEventHelper` --- .../hippy/views/hippylist/RecyclerViewEventHelper.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/views/hippylist/RecyclerViewEventHelper.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/views/hippylist/RecyclerViewEventHelper.java index c398aaab860..445e822f480 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/views/hippylist/RecyclerViewEventHelper.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/views/hippylist/RecyclerViewEventHelper.java @@ -260,8 +260,10 @@ public void sendOnScrollEvent() { } private void observePreDraw() { - if (!isInitialListReadyNotified && viewTreeObserver == null) { - viewTreeObserver = hippyRecyclerView.getViewTreeObserver(); + if (!isInitialListReadyNotified) { + if (viewTreeObserver == null) { + viewTreeObserver = hippyRecyclerView.getViewTreeObserver(); + } viewTreeObserver.addOnPreDrawListener(preDrawListener); } } @@ -396,7 +398,9 @@ public void onViewAttachedToWindow(View v) { @Override public void onViewDetachedFromWindow(View v) { - + if (!isInitialListReadyNotified && viewTreeObserver != null) { + viewTreeObserver.removeOnPreDrawListener(preDrawListener); + } } @Override