From c9e48bd2dff2b5766589024cf7264189b5f2a05c Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期五, 03 一月 2025 14:03:33 +0800 Subject: [PATCH] cpp释放java占用内存 --- iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm b/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm index 939e6ba..a3a8867 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm +++ b/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm @@ -17,7 +17,21 @@ { PyGILThreadLock lock; - PyObject* pModule = create_py_module("${pyModule}.${pyName}"); + + jclass hashmapClass = env->FindClass("java/util/HashMap"); + jmethodID getMID = env->GetMethodID(hashmapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); + jstring keyJString = env->NewStringUTF("pyFile"); + jobject javaValueObj = env->CallObjectMethod(settings, getMID, keyJString); + jstring javaStringValue = (jstring)javaValueObj; + const char* strValue = env->GetStringUTFChars(javaStringValue, NULL); + //*************导入模型****************** + PyObject* pModule = create_py_module(strValue); + // 释放java占用内存 + env->ReleaseStringUTFChars(javaStringValue, strValue); + env->DeleteLocalRef(javaStringValue); + env->DeleteLocalRef(javaValueObj); + env->DeleteLocalRef(keyJString); + env->DeleteLocalRef(hashmapClass); if (pModule == NULL) { cout << "model error" << endl; -- Gitblit v1.9.3