We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
案例: this.timer = setInterval(async () => { console.log('每隔 1s 执行一次'); }, 1000);
每次执行JSValue都会增加一个。
extern "C" JNIEXPORT jobject JNICALL Java_com_didi_hummer_core_engine_napi_jni_JSEngine_callFunction(JNIEnv *env, jclass clazz, jlong js_context, jlong thisObj, jlong funcObj, jobjectArray params) { auto globalEnv = JSUtils::toJsContext(js_context);
NAPIHandleScope handleScope; napi_open_handle_scope(globalEnv, &handleScope); NAPIValue jsThisObj = JSUtils::toJsValue(globalEnv, thisObj); NAPIValue jsFuncObj = JSUtils::toJsValue(globalEnv, funcObj); auto paramsCount = static_cast<int>(env->GetArrayLength(params)); if (jsFuncObj == nullptr) { return nullptr; } auto values = new NAPIValue[paramsCount]; for (int i = 0; i < paramsCount; i++) { jobject obj = env->GetObjectArrayElement(params, i); values[i] = JSUtils::JavaObjectToJsValue(globalEnv, obj); env->DeleteLocalRef(obj); } if (jsThisObj == nullptr) { jsThisObj = JSUtils::createJsUndefined(globalEnv); } NAPIValue result; auto status = napi_call_function(globalEnv, jsThisObj, jsFuncObj, paramsCount, values, &result); if (status == NAPIExceptionPendingException) { reportExceptionIfNeed(globalEnv); napi_close_handle_scope(globalEnv, handleScope); return nullptr; } delete[] values; jobject r = JSUtils::JsValueToJavaObject(globalEnv, result, true); napi_close_handle_scope(globalEnv, handleScope); return r;
} 原因是每次调用 NAPIValue result; 都会返回一个Promise,导致JSUtils::JsValueToJavaObject(globalEnv, result, true)的使用做了强制+1,从而导致内存不释放
The text was updated successfully, but these errors were encountered:
async 会返回一个promise,普通的回调是正常的
Sorry, something went wrong.
No branches or pull requests
案例:
this.timer = setInterval(async () => {
console.log('每隔 1s 执行一次');
}, 1000);
每次执行JSValue都会增加一个。
extern "C"
JNIEXPORT jobject JNICALL
Java_com_didi_hummer_core_engine_napi_jni_JSEngine_callFunction(JNIEnv *env, jclass clazz, jlong js_context, jlong thisObj, jlong funcObj, jobjectArray params) {
auto globalEnv = JSUtils::toJsContext(js_context);
}
原因是每次调用 NAPIValue result; 都会返回一个Promise,导致JSUtils::JsValueToJavaObject(globalEnv, result, true)的使用做了强制+1,从而导致内存不释放
The text was updated successfully, but these errors were encountered: