Fix remove source memory leak. (#412)

* Fix remove source memory leak.

* Fix testcase crash
This commit is contained in:
Kevin Li
2020-06-03 17:26:21 +08:00
committed by GitHub
parent fccf513c0f
commit b16d47ce03
2 changed files with 9 additions and 5 deletions

View File

@@ -110,10 +110,10 @@ namespace android {
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
static auto releaseThreads = javaClass.GetMethod<void ()>(*_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,

View File

@@ -76,6 +76,10 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
}
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
@@ -209,7 +213,7 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
// Release the strong reference to the java peer
assert(javaPeer);
javaPeer.release();
javaPeer.reset();
rendererFrontend = nullptr;
}