Search code examples
androidandroid-mediaplayerandroid-logcatringtone

Why do I occasionally see "MediaPlayer finalized without being released" in logcat even though I'm not using MediaPlayer anywhere?


I am, however, using RingtoneManager to get Ringtones.


This information is already contained in this question and answer, but Googlers are not likely to find it unless they already know what to search for (at least I could not).


Solution

  • It's because RingtoneManager.getRingtone() internally calls open() on the returned Ringtone object. Ringtone.open() sets up a MediaPlayer, and this MediaPlayer does not get released unless you manually call Ringtone.stop(). Note that you do not need to actually play the ringtone for this to be true. This does not appear to be documented anywhere.

    I don't know how much actual harm there is in neglecting to release a MediaPlayer (the documentation provides a worst-case scenario), but manually calling stop() on your Ringtones before letting them get GC'ed will at least silence the warning.