audio - Memory leak while playing sounds with java -
this code playing sounds:
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(); } } }
if call sound.playsound("xxx.wav"); many times see ram according task manager starts rise dramatically. how clean up?
try close method. javadoc:
void close() closes line, indicating system resources in use line can released. if operation succeeds, line marked closed , close event dispatched line's listeners.
Comments
Post a Comment