这是我播放声音的代码:
public class Sound {
public static void playSound(String path)
{
try
{
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(path));
clip.open(inputStream);
inputStream.close();
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
如果我调用 Sound.playSound("xxx.wav");很多时候,我看到任务管理器显示我的内存开始急剧上升。我该如何清理它?
最佳答案
尝试 close 方法。来自 JavaDOC:
void close() Closes the line, indicating that any system resources in use by the line can be released. If this operation succeeds, the line is marked closed and a CLOSE event is dispatched to the line's listeners.
关于java - 用java播放声音时内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23246017/