I am attempting to debug an application that is hanging. The program uses a queue implemented with a LinkedList
, and during stress testing I've discovered that the program stops responding due to running out of heap memory. I analyzed the heap dump and found that memory seems to be leaking from the LinkedList
.
The relevant part of the heap dump:
▶java.net.Vectior @ 0xff5eacd0
▶▶java.util.Vector @ 0xff629f30
▶▶▶java.lang.Object[1280] @ 0xff629f50
▶▶▶▶class com.itnade.vsm.staticobject.TrapQueue @ 0xff6b23e8
▶▶▶▶▶java.util.LinkedList @ 0xff6b2460
▶▶▶▶▶▶java.util.LinkedList$Node @ 0xfb954560
▶▶▶▶▶▶java.util.LinkedList$Node @ 0xfb959968
▶▶▶▶▶▶java.util.LinkedList$Node @ 0xfb95ede8
▶▶▶▶▶▶java.util.LinkedList$Node @ 0xfb964230
▶▶▶▶▶▶java.util.LinkedList$Node @ 0xfb969638
...
...
As you can see from the dump, the LinkedList$Node
s are not deleted, and accumulate.
The general flow of the program is:
Queue.offer() → Queue.poll → Queue.remove(object)
Why does the LinkedList
appear to be leaking memory, and how can I prevent this from happening?