My Java application heap dump shows that a specific lambda used in my class has locked up some amount of memory and its not being released during GC.
Heap shows the specific anonymous lambda class as ParentClass$$Lambda$ID and in current case, the ID is 79(image attached). This ID does not seem to have any relation with the number of lambdas that exist in the class and hence we cannot conclude on which lambda is represented. I'm interested to point at the exact lambda expression as it helps in analyzing, fixing and testing the scenarios related.
Decompiling the class file with DJ did not help as it recreates the lambda expressions to a readable code. Let me know if any ideas on this.
We will first start the Memory Analyzer Tool and open the heap dump file. In Eclipse MAT, two types of object sizes are reported: Shallow heap size: The shallow heap of an object is its size in the memory. Retained heap size: Retained heap is the amount of memory that will be freed when an object is garbage collected.
If you are trying to test memory leakage in your application all you have to do is to identify the object which gets accumulated in the heap every time you access the application. To effectively identify the objects first take and initial heap. Then perform some action in your application.
Right-click on one of the Java process. Click on the 'Heap Dump' option on the drop-down menu. Heap dump will be generated. File path where heap dump is generated will be specified in the Summary Tab > Basic Info > File section.
A heap dump is a snapshot of all the objects that are in memory in the JVM at a certain moment. They are very useful to troubleshoot memory-leak problems and optimize memory usage in Java applications. Heap dumps are usually stored in binary format hprof files.
Try defining the system property
jdk.internal.lambda.dumpProxyClasses=/path/to/dir
when invoking the JVM. This will cause the runtime to write the dynamically generated lambda classes to disk, where you can inspect them with javap
. This will enable you to see what fields (captured variables) they hold, and what lambda body method the lambda corresponds to.
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