diff --git a/engine/src/flutter/shell/platform/android/android_image_generator.cc b/engine/src/flutter/shell/platform/android/android_image_generator.cc index d5255af97b..d3bb70f60d 100644 --- a/engine/src/flutter/shell/platform/android/android_image_generator.cc +++ b/engine/src/flutter/shell/platform/android/android_image_generator.cc @@ -96,14 +96,17 @@ void AndroidImageGenerator::DoDecodeImage() { JNIEnv* env = fml::jni::AttachCurrentThread(); - fml::jni::ScopedJavaLocalRef direct_buffer( - env, env->NewDirectByteBuffer(const_cast(data_->data()), - data_->size())); + // This task is run on the IO thread. Create a frame to ensure that all + // local JNI references used here are freed. + fml::jni::ScopedJavaLocalFrame scoped_local_reference_frame(env); + + jobject direct_buffer = + env->NewDirectByteBuffer(const_cast(data_->data()), data_->size()); auto bitmap = std::make_unique>( - env, env->CallStaticObjectMethod( - g_flutter_jni_class->obj(), g_decode_image_method, - direct_buffer.obj(), reinterpret_cast(this))); + env, env->CallStaticObjectMethod(g_flutter_jni_class->obj(), + g_decode_image_method, direct_buffer, + reinterpret_cast(this))); FML_CHECK(fml::jni::CheckException(env)); if (bitmap->is_null()) {