I am trying to find memory leaks in a program I did not design (I’m new to the project). As it is quite a large program, I am having some trouble. I have tried a few profilers, and most of them hang or crash when attempting to follow the allocation stack trace to see which objects are taking up all of the memory.
I am running System.gc(); in a Thread and attempting to find out what exactly it is releasing/freeing. From the profiler, I can see that it is releasing, but I need to know what it is releasing.
Is there some way to get information at runtime from the garbage collector as to which objects it is releasing/freeing?
If not, or if this is a bad way to even think about trying to approach this, any other suggestions would be appreciated.
I would use a memory profiler to find a memory leak. You can start with VisualVM. this may find your problem, but if it doesn’t try an evaluation version of a commercial profiler like YourKit.
These tools can not only tell you what is being discarded but where it is being creating in the first place. It has a graphical interface so you can see the biggest or most numerous.