Java Memory Leak in FIFO queue implementation -


I read some material about Java memory leak, it implements the FIFO queue to leak memory with sticks is. But I do not understand why this will create memory leakage. Is it because he removed the unused slot in the 'pop' operation? Can anyone explain me?

  queue [head] = null  

The implementation of FIFO queue is as follows:

  public class FIFOQueue {personal Object [] queue; Private integer size = 0, head = 0, tail = 0; Private static final full INITIAL_CAPACITY = 16; Public FIFOQueue () {Qi = New Item [INITIAL_CAPACITY]; } Public Zero Push (object e) {confirmCapacity (); Queue [tail] = e; Size ++; Tail = increase in salary (tail); } Public Object Pop () throws EmptyStackException {if (size == 0) New empty stack exception (); Shape-; Object return value = queue [head]; Head = increment (head); Return return value; } / ** Each time the array needs to be increased to double the capacity. * / Private ability to ensure zero () {if (qi length == size) queue = arrays.copyOf (queue, 2 * size + 1); } / ** Make sure the points are wrapped at the end of the array / private intent (int x) {if (++ x == queue.length) x = 0; Return x; }}  

You answered your question :)

You do not clean the Qatar collector collector, it can not be cleared from memory, because you have valid references in your FIEQQE of this object. In this way you pollute your memory with unused objects, effectively reduce memory for your program.

Along with this it is stated in the comments that your sure capacitance function will only work, when the tail is at the end of an array, otherwise you will lose the elements in your line at Push, this line [head ] The reference problem is more important.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -