diff --git a/ddprof-lib/src/main/cpp/livenessTracker.cpp b/ddprof-lib/src/main/cpp/livenessTracker.cpp index 61e17f8bc..840f6c606 100644 --- a/ddprof-lib/src/main/cpp/livenessTracker.cpp +++ b/ddprof-lib/src/main/cpp/livenessTracker.cpp @@ -370,7 +370,10 @@ void LivenessTracker::track(JNIEnv *env, AllocEvent &event, jint tid, } else { Log::debug("Cannot add sampled object to Liveness tracking table, it's " "overflowing"); + env->DeleteWeakGlobalRef(ref); } + } else { + env->DeleteWeakGlobalRef(ref); } } skipped = 0; // reset the subsampling skipped bytes