Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The implementation of global and local references was completely overhauled in ICS, with intention to improve memory management on the Java side. Find the explanation in <a href="http://developer.android.com/guide/practices/jni.html" rel="nofollow noreferrer">developers guide</a> Read more in the <a href="http://android-developers.blogspot.com/2011/11/jni-local-reference-changes-in-ics.html" rel="nofollow noreferrer">developers blog</a>.</p> <p>In the nutshell, whatever you receive in a JNI function, including the <code>globalRef</code> parameter of <code>freeNativeBuffer()</code> function, are <strong>local references</strong>. You can create and keep a global reference in your C code, like this:</p> <pre><code>static jobject globalRef; allocNativeBuffer(JNIEnv* env, jobject cls, jlong size) { void* buffer = malloc(size); jobject directBuffer = env-&gt;NewDirectByteBuffer(buffer, size); globalRef = env-&gt;NewGlobalRef(directBuffer); return directBuffer; } freeNativeBuffer(JNIEnv* env, jobject cls, jobject localRef) { void *buffer = env-&gt;GetDirectBufferAddress(localRef); if (buffer == env-&gt;GetDirectBufferAddress(globalRef) { /* we received the object that we saved */ env-&gt;DeleteGlobalRef(globalRef); free(buffer); } } </code></pre> <p><strong>PS</strong> I found the <a href="https://stackoverflow.com/questions/5060307/bytebuffer-not-releasing-memory">stackoverflow discussion</a> which looks like the inspiration for your experiment. See the <a href="https://stackoverflow.com/questions/5060307/bytebuffer-not-releasing-memory#9891217">answer</a> which explains that there was no need to create and delete global references in the first place.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload