gpt4 book ai didi

Android TextView内存泄漏

转载 作者:太空狗 更新时间:2023-10-29 13:32:54 25 4
gpt4 key购买 nike

我正在开发一个音乐应用程序,其中使用了一个 Seekbar。我有一种方法可以处理搜索栏性能,并且效果很好。但如果 seekbar 正在运行,则会出现内存泄漏,并且 Log cat 会显示为

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

seekbar 进行时持续出现

我发现问题是由于 TextView 的动态更新,即显示歌曲的当前持续时间。

我该如何解决。请帮我解决这个问题

我的功能是

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);
}

最佳答案

GC_CONCURRENT 行并不意味着您有内存泄漏。这只是垃圾收集器清理未使用的内存。

编辑这一行:

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

不会造成内存泄漏(除非 getActualDuration() 做了一些有趣的事情)。它只是每 500 毫秒创建一个新的 String 但这不是内存泄漏。旧的将像您的情况一样被垃圾收集。

关于Android TextView内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13581026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com