Search code examples
androidcandroid-ndkopensl

Does a finished buffer from an OpenSL ES audio player need to be freed?


Just for confirmation. When an audio player, created via OpenSL ES for Android, finishes playing a buffer, is that buffer automatically freed by the Garbage collector? Or do I need to free the buffer myself?

If it is the latter, I could use some help. But as for now, I won't post any code until I get told that I need to do it myself...


Solution

  • The buffer queue doesn't actually allocate buffer memory itself (or need to free it), you pass in pointers to memory you have allocated via the 'enqueue' function. You will need to free the memory you allocated when you're finished playing buffers.

    As OpenSL ES is a native library in C++, it knows nothing of garbage collection, any memory you allocate for the API must be freed by you, and objects you create must have 'destroy' called on them to clean up internal memory.