3

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);
    }
Zombie
  • 1,965
  • 2
  • 20
  • 34
Arundas K V
  • 801
  • 2
  • 14
  • 28
  • Why do you want to update the length of the track with every seekbar progress? you can update it once after the MediaPlayer is prepared. – Rotem Nov 27 '12 at 09:30
  • i want to update the current seeking time in one Textview, there is one more Textview for full duration of song,this textview for curent time of song which is playing. – Arundas K V Nov 27 '12 at 09:32
  • how often do you change the seekbar progress? If you don't show milliseconds in your text, you can make a thread that every second updates the TextView according to the seekbar. – Rotem Nov 27 '12 at 09:36
  • what my objective is: if a song having maximum duration 10000ms, oneof my textview maxTime,which is outside of this method,will show it as 00:10 , by passing the ms inside a method getActualDuration(timeInMillis)...Need to show one more TextView currTime, as the current position of song. eg: wen the song starts playing, it is set to 0, then aftr 1 second it will update as, 00:01, 00:02, 00:02 etc etc upto 00:10 ...like that – Arundas K V Nov 27 '12 at 09:42
  • The logcat entry you show does not mean a memory leak, it's simply the garbage collector doing it's job. I suspect this `""+currPos` is causing a lot of garbage collection. Please read about Java "immutable string". – Simon Nov 27 '12 at 09:58
  • ok, thanks, getActualDuration() is a method which accepts a string variable in the form of some milliseconds, and return a string in the form of actual time representation. eg: 10000ms to 00:10. currPos is a int variable , tried to make it as a string. – Arundas K V Nov 27 '12 at 10:04

1 Answers1

2

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.

Caner
  • 57,267
  • 35
  • 174
  • 180
  • thanks, but, how can i avoid leaving memory unused, in this case. when i commented out this line currTime.setText(getActualDuration(""+currPos)); there is no GC_CONCURRENT, releasing unused memory. so i confused – Arundas K V Nov 27 '12 at 09:49
  • Which line are you talking about? In java generally you don't need to worry too much about memory leaks. If there is an unused object it will be freed automatically(unless you keep a reference to it somewhere). – Caner Nov 27 '12 at 09:51
  • (working on Android) this line currTime.setText(getActualDuration(""+currPos)); in Log cat, messages similar to this coming continuosly. GC_CONCURRENT freed 1692K, 34% free 10759K, paused 3ms+8ms will it cause any performance issue, – Arundas K V Nov 27 '12 at 09:55
  • check my edit, that is probably the line causing those messages in the log but it is fine – Caner Nov 27 '12 at 10:02
  • yes i know the GC_CONCURRENT is due to this line, dont know how to fix it. must to show the currTime in every second – Arundas K V Nov 27 '12 at 10:22