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 |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 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 ddf78cf..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
@@ -22,10 +22,16 @@
 		jmethodID getMID = env->GetMethodID(hashmapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
 		jstring keyJString = env->NewStringUTF("pyFile");
 		jobject javaValueObj = env->CallObjectMethod(settings, getMID, keyJString);
-		const char* strValue = env->GetStringUTFChars((jstring)javaValueObj, NULL);
-
+		jstring javaStringValue = (jstring)javaValueObj;
+		const char* strValue = env->GetStringUTFChars(javaStringValue, NULL);
+		//*************导入模型******************
 		PyObject* pModule = create_py_module(strValue);
-		/*PyObject* pModule = create_py_module("${pyModule}.${pyName}");*/
+		// 释放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