diff --git a/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.cc b/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.cc index 387a0b17e252..5c704c9646a2 100644 --- a/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.cc +++ b/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.cc @@ -247,9 +247,6 @@ JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxImperativeInvokeEx cParamVals, &cOutStypes); env->ReleaseLongArrayElements(inputs, cInputs, 0); - if (cOutputsGiven) { - env->ReleaseLongArrayElements(outputsGiven, cOutputsGiven, 0); - } // release allocated memory if (numParams > 0) { @@ -284,6 +281,10 @@ JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxImperativeInvokeEx } } + if (cOutputsGiven) { + env->ReleaseLongArrayElements(outputsGiven, cOutputsGiven, 0); + } + return ret; }