Take the 2-minute tour ×

SOLVED: needed to declare MP globally.

I have a MediaPlayer playing/looping a sound.

    MediaPlayer mp = MediaPlayer.create(this, R.raw.v);

and it works fine until I suddenly get

D/dalvikvm(14090): GC_CONCURRENT freed 1841K, 51% free 4335K/8839K, external 10702K/12379K, paused 2ms+4ms

in logcat and MP dies. Any ideas what might have happened and how do I fix that?


share|improve this question
add comment

2 Answers

Add this line before mp.start()


Then set false when you want to stop it looping.

share|improve this answer
Thanks. Just tried it. same result, dies with "GC_CONCURRENT freed..." –  Roger Travis Jun 29 '12 at 16:41
add comment

Got it! Just needed to declare MP globally and it works!

share|improve this answer
You mean you've added it to a member variable or static variable. The reason it was released is because as a local variable, it came out of scope when your method has returned, i.e. you had no reference to it (no directed path existed to it from none of the GC roots, to be precise). Therefore, it was eligible for garbage collection, and its finalizer was run. The managed finalizer of MediaPlayer calls it native finalizer, which in turns releases the underlying native MediaPlayer/AudioTrack. This is why your sound playback died. –  Thomas Calc Jun 29 '12 at 17:08
add comment

Your Answer


