Discussion:
native heap question--JNI related
S.G. Vogel
2018-08-31 02:18:54 UTC
Permalink
https://www.badlogicgames.com/wordpress/?p=2367 seems to say that if you
create a direct buffer in native code you avoid GC because the memory is
allocated on the native heap.

var buffer = allocateDirect()...//allocates on the java heap as well

var buffer= nativeBufferMethod. //still has a pointer on the java side


From GoogleIO17 talk I learned that the java side variable pointer to the
native object should be coordinated with a native delete via creation of a
phantom reference and a callback from the referencequeue addition of it.
I also have read on SO that the native object gets cleaned up when the java
pointer gets GC'd.


Because ART/Dalvik can reclaim the process or *any* memory when it runs low
at any time, I write to disk onStop and onLowMemory/onTrimMemoryand then
check in onStart.

Is there any technique to keep the pointer to the native heap allocation
alive that I have not thought about from the perspective of the
NDK?(besides writing the app entirely in C/C++)?


thanks!
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/52b1ac1d-31f2-4999-a5d8-54da7263f4e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...