Arundas K V
Arundas K V

Reputation: 809

Android TextView Memory Leakage

I am developing a Music Application, in which a Seekbar is being used. I have one method which handles the seekbar performance, and which works well. but if seekbar is in action there is a memory leakage and the Log cat shows like

GC_CONCURRENT freed 1692K, 34% free 10759K, paused 3ms+8ms

this is coming continuously when the seekbar is progressing

i found that the problem is due to the updation of TextView, dynamically, which is to show the current duration of song.

how can i fix that. please help me for this issue

My function is

public void seekbarProgress(){

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                //current position of the play back 
                currPos = harmonyService.player.getCurrentPosition();
                if(isPaused){
                    //if paused then stay in the current position
                    seekBar.setProgress(currPos);
                    //exiting from method... player paused, no need to update the seekbar
                    return;
                }

                //checking if player is in playing mode
                if(harmonyService.player.isPlaying()){
                    //settting the seekbar to current positin
                    seekBar.setProgress(currPos);
                    //updating the cuurent playback time
                    currTime.setText(getActualDuration(""+currPos));
                    handler.removeCallbacks(this);
                    //callback the method again, wich will execute aftr 500mS
                    handler.postDelayed(this, 500);
                }
                //if not playing...
                else{
                    //reset the seekbar
                    seekBar.setProgress(0);
                    //reset current position value
                    currPos = 0;
                    //setting the current time as 0
                    currTime.setText(getActualDuration(""+currPos));
                    Log.e("seekbarProgress()", "EXITING");
                    //exiting from the method
                    return;
                }
            }
        }, 500);
    }

Upvotes: 3

Views: 1588

Answers (1)

Caner
Caner

Reputation: 59150

GC_CONCURRENT lines does not mean that you have a memory leak. It's just garbage collector cleaning unused memory.

EDIT This line:

currTime.setText(getActualDuration(""+currPos));

Does not create a memory leak(unless getActualDuration() does something funny). It's just creates a new String every 500ms but it is not a memory leak. The old one will be garbage collected as in your case.

Upvotes: 2

Related Questions