Media::Player memory management

Media::Player memory management

BY 25 Oct 2013 Native Application Development

I was wondering when I used Media::Player::OpenBuffer if it release the buffer memory when I close the player or start a new buffer?

At the moment I keep a pointer to the buffer and release it manually when I stop the player. But I’m getting a rare crash on a consequent OpenBuffer calls on malloc_consolidate and I’m wondering if I’m doing a double delete.

This is a simplified version of my code:

result TizenMediaPlayer::StartAudio()
{
    if (mCurrentByteBuffer != null) {
        AppAssertf(false, "Possible memory leak the buffer should be null");
        delete mCurrentByteBuffer;
    }

    mCurrentByteBuffer = new (std::nothrow) Tizen::Base::ByteBuffer();
    mCurrentByteBuffer->Construct(audioRequest.length);

    tFile.Construct(filename, L"rb");
    tFile.Read(*mCurrentByteBuffer);
    r = mPlayer.OpenBuffer(*mCurrentByteBuffer, false);
    mPlayer.Play();
    ...
}
void TizenMediaPlayer::Stop(void)
{
    PlayerState state = mPlayer.GetState();
    if (state == PLAYER_STATE_PAUSED || state == PLAYER_STATE_PLAYING) {
        mPlayer.Stop();
    }
    state = mPlayer.GetState();
    if (state == PLAYER_STATE_OPENED || state == PLAYER_STATE_ENDOFCLIP || state == PLAYER_STATE_STOPPED) {
        mPlayer.Close();
    }
    if (mCurrentByteBuffer)
    {
        AppLog("Delete Media buffer");
        delete mCurrentByteBuffer;
        mCurrentByteBuffer = null;
   }
   ...
}

As you can see I keep a pointer to mCurrentByteBuffer and then delte it when Stop() is called. Stop() is called by END_OF_FILE callback or if we decide to stop the player for any reason.

The documentation does not cover this topic so any information will help.

Thanks for your help.

Written by