Think about this situation in jni:
- I first call a native function1 in java
- The native function1 calls the java function2
- The java function2 calls the native function3
What I need to know is when will the LocalReference created in function3 be automatically released. Is it the time the function3 returns or the time the function1 returns?
I tried to ask gpt4 and claude3. The answer of gpt4 is the time function1 returns. The answer of claude3 is the time function3 returns.
the answer is when the native call will return to java, so when function3 returns back to function2 in java. Local references are valid for the duration of a native method call. They are freed automatically after the native method returns.
For more android related reference :
https://developer.android.com/training/articles/perf-jni#local-and-global-references