fix mem leak

This commit is contained in:
yefeng 2022-04-11 10:22:50 +08:00
parent 9fb5c18c60
commit 89b26288fe
2 changed files with 6 additions and 3 deletions

View File

@ -117,6 +117,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_com_mindspore_ModelParallelRunner_pred
auto &ms_tensor = *static_cast<mindspore::MSTensor *>(tensor_pointer);
c_inputs.push_back(ms_tensor);
}
env->ReleaseLongArrayElements(inputs, input_data, JNI_ABORT);
std::vector<mindspore::MSTensor> outputs;
pointer->Predict(c_inputs, &outputs);
for (auto &tensor : outputs) {

View File

@ -276,8 +276,10 @@ extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_MSTensor_createTensorByNat
c_shape[i] = static_cast<int64_t>(shape_pointer[i]);
}
env->ReleaseIntArrayElements(tensor_shape, shape_pointer, JNI_ABORT);
auto tensor =
mindspore::MSTensor::CreateTensor(env->GetStringUTFChars(tensor_name, JNI_FALSE),
static_cast<mindspore::DataType>(data_type), c_shape, p_data, data_len);
const char *c_tensor_name = env->GetStringUTFChars(tensor_name, nullptr);
std::string str_tensor_name(c_tensor_name, env->GetStringLength(tensor_name));
auto tensor = mindspore::MSTensor::CreateTensor(str_tensor_name, static_cast<mindspore::DataType>(data_type), c_shape,
p_data, data_len);
env->ReleaseStringUTFChars(tensor_name, c_tensor_name);
return jlong(tensor);
}