If you try to run Eclipse Memory Analyzer (MAT) out of the box on macOS, you’ll likely get an error that you need version 11 or above of Java, even if you have version 11 installed (say, with SDKMAN!).
You need to tell Eclipse MAT where to find this version of Java. Don’t edit the info.plist file, because then you’ll get an invalid code signature error.
Instead, you want to edit the /Applications/mat.app/Contents/Eclipse/MemoryAnalyzer.ini file. I added the following two lines to the top of my file:
Worked like a charm. (Note that adding these to the bottom of the file didn’t work).
I also had to increase the size of the heap. I bumped it to 12GB, by editing the appropriate line in MemoryAnalyzer.ini to:
Final note: you may want to show Unreachable objects. I’m just going to copy-paste from this Stack Overflow answer.
- Close the snapshot
- Select the heap dump using Window > Heap Dump History right-click, Delete Index Files
- Select ‘Keep unreachable objects’ using Window > Preferences > Memory Analyzer
- Reopen the heap dump, which will reparse the heap dump.
- Select the Java Basics > GC Roots query.
- Select the ‘Unreachable Objects’ row.
- Run the ‘Show Retained Set’ query on that row.