Reputation: 1003
I have been reading about this article:
Since I myself have issues with threads:
Does this mean that Long running threads in Java will create memory leaks? What if I need to have a long running thread in the first place. Isn't most application long running threads also?
Upvotes: 2
Views: 1987
Reputation: 5706
Long running thread doesn't create memory leak. It is what you do inside it. Technically memory leaks happens when garbage collector could not collect free space, as the space is marked as being used. i.e. if references are held.
Now in a long running thread, you could have an object reference present for the lifetime of the thread. This object itself could be expensive. This is the case in first link you shared(threadlocal holding transitively all the references)
On your second link, the problem seems to lie somewhere. Here what I generally do if I suspect memory leak
Repeat multiple times, you will notice some objects, which should have been cleared. This will give you some idea. Following those references in code you can get some idea.
Upvotes: 3