thoma
thoma

Reputation: 583

Is setting Android MediaPlayer player to null when releasing necessary?

Looking at the example on how to release an Android MediaPlayer instance on the official document, it is says that we should nullify the object after releasing it:

Here's how you should release and then nullify your MediaPlayer:

mediaPlayer.release();
mediaPlayer = null; // <-- instruction I am asking about.

Is this actually necessary? If so, why?

Source: https://developer.android.com/guide/topics/media/mediaplayer.html#releaseplayer

Upvotes: 5

Views: 1172

Answers (1)

TDG
TDG

Reputation: 6151

The null is to mark the GC that it can 'collect' that object.

Upvotes: 4

Related Questions