Skip to content

Commit 3544e86

Browse files
committed
todo:引用计数优化点说明
1 parent e64302c commit 3544e86

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

native/cpp/quickjs_wrapper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,16 @@ JSValue QuickJSWrapper::jsFuncCall(int callback_id, JSValueConst this_val, int a
739739
// JS 对象作为方法返回值,需要引用计数加1,不然会被释放掉
740740
if (JS_IsObject(jsValue) && !jniEnv->IsInstanceOf(result, jsCallFunctionClass)) {
741741
JS_DupValue(context, jsValue);
742+
743+
// todo 这里有一个引用计数优化点
744+
// 1. 通过 Java 层创建的 JSObject 会被计数加1,上面的 JS_DupValue 会加1,
745+
// 2. 也就是会有两次引用,在函数执行完会减1,因为还有一次引用不会被释放。
746+
// 3. 优化方式一:注释掉上面的 JS_DupValue 代码,放开下面的注释代码。
747+
// map<jlong, JSValue>::iterator exist;
748+
// exist = values.find(reinterpret_cast<jlong>(JS_VALUE_GET_PTR(jsValue)));
749+
// if (exist != values.end()) {
750+
// values.erase(exist);
751+
// }
742752
}
743753

744754
jniEnv->DeleteLocalRef(result);

0 commit comments

Comments
 (0)