From 0b3f46b564d539d8f74473caaed90cebe557dc5c Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Sat, 12 Sep 2020 21:50:51 -0700 Subject: [PATCH] Deallocate JNI array after TextInput text measurement Summary: Every time we measure a TextInput we allocate a JNI local array and weren't cleaning it up, leading to JNI table exhaustion. Changelog: [Internal] Differential Revision: D23670780 fbshipit-source-id: 2ecf9770c8593eeadd70a248be58037fefdca61e --- .../renderer/textlayoutmanager/TextLayoutManager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp b/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp index 0c9ae885e85..3d69b4a84ed 100644 --- a/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp +++ b/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp @@ -88,6 +88,10 @@ TextMeasurement TextLayoutManager::measureCachedSpannableById( maximumSize.height, attachmentPositions)); + // Clean up allocated ref - it still takes up space in the JNI ref table even + // though it's 0 length + env->DeleteLocalRef(attachmentPositions); + // TODO: currently we do not support attachments for cached IDs - should we? auto attachments = TextMeasurement::Attachments{}; @@ -172,8 +176,10 @@ TextMeasurement TextLayoutManager::doMeasure( } } } - // DELETE REF + + // Clean up allocated ref env->DeleteLocalRef(attachmentPositions); + return TextMeasurement{size, attachments}; }