From 1159d99089b7ea6d45cca3aa469a98922f8c096a Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 16 Jul 2020 11:36:01 +0800 Subject: Fix remove source memory leak. Cherry-pick from https://github.com/mapbox/mapbox-gl-native-android/pull/412 --- platform/android/src/style/sources/custom_geometry_source.cpp | 8 ++++---- platform/android/src/style/sources/source.cpp | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/platform/android/src/style/sources/custom_geometry_source.cpp b/platform/android/src/style/sources/custom_geometry_source.cpp index dccca4cf46..5def7b7ea9 100644 --- a/platform/android/src/style/sources/custom_geometry_source.cpp +++ b/platform/android/src/style/sources/custom_geometry_source.cpp @@ -111,10 +111,10 @@ namespace android { static auto& javaClass = jni::Class::Singleton(*_env); static auto releaseThreads = javaClass.GetMethod(*_env, "releaseThreads"); - assert(javaPeer); - - auto peer = jni::Cast(*_env, javaClass, javaPeer); - peer.Call(*_env, releaseThreads); + if(javaPeer) { + auto peer = jni::Cast(*_env, javaClass, javaPeer); + peer.Call(*_env, releaseThreads); + } }; bool CustomGeometrySource::isCancelled(jni::jint z, diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp index 786e5cb586..485f4284e4 100644 --- a/platform/android/src/style/sources/source.cpp +++ b/platform/android/src/style/sources/source.cpp @@ -67,6 +67,10 @@ namespace android { } Source::~Source() { + if (ownedSource) { + ownedSource.reset(); + ownedSource.release(); + } // Before being added to a map, the Java peer owns this C++ peer and cleans // up after itself correctly through the jni native peer bindings. // After being added to the map, the ownership is flipped and the C++ peer has a strong reference @@ -137,7 +141,7 @@ namespace android { // Release the strong reference to the java peer assert(javaPeer); - javaPeer.release(); + javaPeer.reset(); rendererFrontend = nullptr; } -- cgit v1.2.1