Just today I discovered memory leak in my app with large number of objects created as anonymous classes. It was classic example that each object had it's own class defined and put into heap.
It wasn't trivial to find in runtime memory profiler and heap dump analysis done by Eclipse Memory Analyzer wasn't helpful neither.
I was wondering how to log all anonymous classes created in runtime with thread id (or at least parent classloader).
I think this single thing alone would make finding root cause trivial.
I'm not sure that listing all anonymous classes will get you anywhere, there are typically a lot of them.
What you probably need is logic to search for instances of classes that are retained by inner classes references (which include anonymous classes).
In JProfiler, there is a corresponding inspection:
The object set create by the inspection contains all such instances and you can then show a paths to a GC root:
Disclaimer: My company develops JProfiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With