JNI: call JAVA method from C ++, returned objects, links and GC

What is the rule when a C ++ program (!) Calls a java method that returns an object? Is there a wonderful link to this object? Should I call "DeleteLocalRef" to make sure the object is GCd, or will it be GCd automatically? The reason why this is not clear to me is that in all the examples and official documentation that indicate that “DeleteLocalRef” is not necessary, it only makes sense to me when the native C / C method runs in Java ++ ". But if the calling thread is a C ++ method calling java, how does the JVM know that the object can be GCd?

On the same lines: if I want to cache an object, should I call "NewGlobalRef"?

Could not find a link to this ...

Thanks for any link and / or clarification

+4
source share
2 answers

I think j.holetzeck's answer left an important part.

From the same documentation :

Implementing Local Links

, Java Java . Java . Java, ( , JNI), . native, .

, , :

:

  • Android Java.
  • Android ++ .
  • ++ ++ Java JNI.

, , 2, ++ Java-, .

++, Java, , - , Java ++ ( : C++->Java->C++), Java, , ++-, GC'd (C++->Java->C++C++->Java).

+2

:

JNI , : . native . , .

. Java, JNI, . JNI . JNI, , Java , . VM .

, . , . , , :

  • Java, Java. . Java , .

  • , . , , . , , . .

JNI . , , JNI- , , .

, . .

0

All Articles