Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need DeleteLocalRef() when calling from C to Java ?

843829Mar 1 2008 — edited Mar 7 2008
I could not figure out if I need to use DeleteLocalRef() on objects that are created when I call java code from C/C++. Consider the following pseudo code example:
void foo( char * string ) 
{
      jstring jstr = env->NewStringUTF(string );

      env->CallVoidMethod( ..., jstr);
      env->DeleteLocalRef( .. jstr );      // <-- IS THIS NEEDED TO AVOID LEAKS ?
}
The JNI documentation mentions that it is usually not necessary to use DeleteLocalRef() when calling from Java to native. The JVM uses local references the are released after the call. But I could not find an answer for the native -> Java calling direction.

/ HaJU

Edited by: Haju_schulz on Mar 1, 2008 3:16 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 4 2008
Added on Mar 1 2008
2 comments
1,829 views