java - Thread not releasing memory -


I am trying to run sound effects in my program using thread, I searched the web and As I have understood when a thread reaches the end of the run function, it will be free to collect GC.

However, when I call the function multiple times, the task manager was a high rise in memory usage and it never went back, I was waiting for GC for 2 minutes but no one There was no impact.

Here is the sound that I use to run sound effects:

  public static zero play sfx (last string path) {new thread (new Runnabal) (Public Zero Run) {tryin audio stream}}; SourceLine = null; AudioFormat AudioFormat = AudioInputStream.formform (); Dataline E.Info info = New DataLine.Info (SourceDataLine.class, audioFormat); SourceLine = (SourceDataLine) audio system. Gateline (notification); SourceLine.open (audioFormat); If return (sourceLine == blank); SourceLine.start (); Int nBytesRead = 0; Byte [] abData = new byte [BUFFER_SIZE]; While (nBytesRead! = -1) {try {nBytesRead = audioInputStream.read (abData, 0, abData.length); } Hold (IOException e) {e.printStackTrace (); } If (nBytesRead> = 0) {sourceLine.write (abData, 0, nBytesRead); }} SourceLine.drain (); SourceLine.close (); AudioInputStream.close (); } Hold (IOException e) {e.printStackTrace (); } Hold (exception e) {e.printStackTrace (); System.exit (1); }         }     }).Start(); }  

What should I do to recover lost memory?

I can not reproduce it For me, this will be about 60k of memory usage, which is considering the language in question is totally IMO. Do you have a small code that reliably presents the problem again?

  public static zero main (string [] args) {for (int i = 0; i  

In addition, what are your expectations on memory usage? It is not easy to predict GC's behavior, and you are not guaranteed that you are waiting for only a while. Especially if you are not allocating a lot.

I will also be able to get rid of attempt to capture in my reading loop. You do not handle any exception anyway, and you keep it even outside the loop. If Stream Io is the cause of exception possibilities then do you want to cancel the loop in any way, right?


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -