While programming in OpenGL on Android one will be using the native nio buffers from the core java package. In many of the opengl samples you will see that these native buffers are being allocated. But you will not see that memory anywhere being "un" allocated. So a question begs to be asked:
Who recovers the memory of allocateDirect of java nio buffers? I did some research on the topic. Here is the summary. The java.nio package is there to allocate memory space outside of the java heap that can be directly used by such systems as OpenGL or file i/o etc. The nio buffers are actually java objects that eventually point to the native buffer. These objects are garbage collected. When they are garbage collected they go ahead and delete the native memory. Java programs doesn't have to do anything special to unallocate or free the memory. However the "gc" won't get fired unless there is memory needed in the java heap. This means you can run out of native memory and gc may not realize it. One implementation in the references below points to an approach where an outof memory exception will trigger a "gc" and tries it again. Importantly for the sake of simple OpenGL under ordinary circumstances one can allocate the native buffers and not worry about releasing explicitly as that is done by the gc. You can read more details of the research at the following url http://www.satyakomatineni.com/akc/display?url=DisplayNoteIMPURL&reportId=3184&ownerUserId=satya --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

