Note that there are some explanatory texts on larger screens.

plurals
  1. POI've "fixed" a memory leak, but.. how to fix it in a better way?
    primarykey
    data
    text
    <p>It was a very fast and makeshift, bug fix.. It worked, but I would like to find a better understanding and solution.</p> <p>This was the Class Constructor generating the leak</p> <pre><code>final transient DataInputStream din; final transient DataOutputStream dout; final transient BufferedReader bin; final transient BufferedWriter bout; NData(Socket sock0) throws IOException { sock=sock0; din= new DataInputStream(sock.getInputStream()); dout = new DataOutputStream(sock.getOutputStream()); bin = new BufferedReader(new InputStreamReader(din)); bout = new BufferedWriter(new OutputStreamWriter(dout)); // .. } </code></pre> <p>The bug fix was to changed it (remove final) so that let me to assign null later</p> <pre><code>transient DataInputStream din; transient DataOutputStream dout; transient BufferedReader bin; transient BufferedWriter bout; NData(Socket sock0) throws IOException { sock=sock0; din= new DataInputStream(sock.getInputStream()); dout = new DataOutputStream(sock.getOutputStream()); bin = new BufferedReader(new InputStreamReader(din)); bout = new BufferedWriter(new OutputStreamWriter(dout)); // .. } //And to add a "magic" destructor void nuller() { din=null; dout=null; bin=null; bout=null; } </code></pre> <p><strong>There was a finish method that ended the thread, closes the streams, so I add there the "nuller" method call, and memory leak went away.</strong></p> <p>Why after finished the thread and closed the stream, it keep allocating memory in "byte[]" ? Why GC don't throw it away ? (except after that dirty with null asignment) </p> <p><strong>EDIT:</strong></p> <p>As casablanca says perhaps the NData object is still around, there is a</p> <pre><code>final static ConcurrentHashMap &lt;String,NData&gt;(); </code></pre> <p>so that have NData as values, A remove(key) is done to purge the object from the Map, but.. it seems not be enough.</p> <p>Removing from a HashMap the only object reference won't be enough to remove the object?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload