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
答:
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
相关文章推荐
- Local and Global References区别
- Local and Global References
- global variable and local variable
- 论文笔记之:Let there be Color!: Joint End-to-end Learning of Global and Local Image Priors for Automatic
- 论文笔记:Improving Deep Visual Representation for Person Re-identification by Global and Local Image-language Association
- C++中关于静态对象的使用( local static object and global static object)
- [CONLL2017] Learning local and global contexts using a convolutional recurrent network model
- [转]Difference among Domain Local Group and Global Group and Universal Group
- C++中关于静态对象的使用( local static object and global static object)
- unity学习积累,关于transform Gizmo当中的四个按钮center、pivot、local、global
- Android中 出现Excessive JNI global references错误的解决方案
- Asp.Net Globalization and Localization using Local Resource files and Global Resource files
- None of the XX first of XX (0) points of the global plan were in the local costmap and free
- 论文笔记之:Let there be Color!: Joint End-to-end Learning of Global and Local Image Priors for Automatic
- 显著性检测总结之Exploiting Local and Global Patch Rarities for Saliency Detection
- Questions about OPENCL global and local work size
- 正则表达式学习指南(十二)----Grouping and Backreferences
- Difference among Domain Local Group and Global Group and Universal Group
- Difference among Domain Local Group and Global Group and Universal Group
- Learning with Local and Global Consistency