1

I have a memory leak in my program that I've been analyzing with JProfiler. There are some string values, which I recognize as originating from my program, that are not getting garbage collected. However, when looking at the Heap Walker in JProfiler I'm not quite sure how to narrow down the source.

JProfiler Screenshot

The string is data coming from some HTML parsing I do, however I'm not certain how there is still a reference to the object. All I see is "thread object". How can I find out where the actual memory leak is? Is that possible?

fbailey
  • 303
  • 5
  • 17

1 Answers1

1

Just looking at the garbage collector root will not always tell you what causes the memory leak, you have to analyze the while reference chain.

The screen shot shows a java.util.Stack object in the reference chain that you have put into a java.lang.ThreadLocal. Thread locals are a common source of memory leaks.

To see which thread local references your objects, select the object(s) of interest in a new object set, then calculate the "Thread locals" inspection in the heap walker.

enter image description here

Ingo Kegel
  • 46,523
  • 10
  • 71
  • 102
  • Thanks @Ingo Kegel, I know personally that I'm not making any ThreadLocal operations, so I'm guessing some underlying library or code is in that case. Do you know if there's any easy way to identify who is making that call in JProfiler? – fbailey Jan 31 '23 at 18:45