您的位置:首页 > Web前端

JNI学习之-----Local and Global References

2012-06-21 17:04 369 查看
1.问: jni 支持多少种 references?

答:

JNI supports three kinds of opaque references: local references, globalreferences, and weak global references.

2.问: Local 和 global references 的生命周期一样吗?

答:

Local references areautomatically freed, whereas global and weak global references remain validuntil they are freed by the programmer.

3.问: local reference 的有效期是怎么样的? 它什么时候产生,什么时候消亡?

答:A local reference is valid only within the dynamic context of the nativemethod that creates it, and only within that one invocation of the native method.All local references created during the
execution of a native method will be freedonce the native method returns.

Local references are also only valid in the thread that creates them. A localreference that is created in one thread cannot be used in another thread. It is a pro-gramming error for a native method
to store a local reference in a global variableand expect another thread to use the local reference.

4.问: 请你介绍一下global references的基本情况?

答:

You can use a global reference across multiple invocations of a native method. Aglobal reference can be used across multiple threads and remains valid until it isfreed by the programmer. Like a local
reference, a global reference ensures thatthe referenced object will not be garbage collected.

5.问: 怎样去创建一个global references ?

答:

global ref-erences are created by just one JNI function,
NewGlobalRef 例如:

d->audio_record = jni_env->NewGlobalRef(d->audio_record);

6.问:怎样去释放Local references ?

答:(*env)->DeleteLocalRef(env, jstr);

7.问:怎样去释放Global references?

答:
DeleteGlobalRef
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐