JNI: the overhead of holding Java object references in native code?

I look forward to integrating JRE into C applications through JNI

What is the cost of holding a large number of Java object references in C applications (Global references in JNI terms)?

What problems should I pay attention to with this method (except for obvious ones, such as manually deallocating references)?

Solution

(a) The overhead is the same as that from Java You are preventing objects from being garbage collected

(b) Unless you execute correctly, holding object references across JNI calls can be fatal to the JVM You need to carefully read the JNI specification for global and local references You also need to consider using weak references instead of global references

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>