89
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid2584.hprof ...
Heap dump file created [106948719 bytes in 4.213 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
at java.util.ArrayList.ensureCapacity(ArrayList.java:167)
at java.util.ArrayList.add(ArrayList.java:351)
at Main.main(Main.java:15)

But when i open head dump java_pid2584.hprof via Eclipse Memory Analyser,but there is always message:

An internal error occurred during: 
"Parsing heap dump from **\java_pid6564.hprof'".Java heap space
Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76
Gavin
  • 891
  • 1
  • 6
  • 5
  • 7
    Did you try increasing the `-Xmx` parameter when launching Eclipse? – Michael Laffargue Mar 22 '12 at 10:02
  • If you "don't have enough RAM" even when specifying -Xmx then http://stackoverflow.com/questions/7254017/tool-for-analyzing-large-java-heap-dumps has some ideas – rogerdpack Apr 01 '15 at 20:42
  • 8
    I laughed so hard when my efforts to analyze a memory error failed as the tools had not enough memory. Hilarious. – James T Snell Jun 15 '16 at 20:46
  • 1
    To go to this file, use finder-> Macintosh hd -> Applications -> right click mat to go to contents folder -> eclipse -> MemoryAnalyzer.ini – Gaurav Dec 18 '21 at 05:07

11 Answers11

140

The problem is that Eclipse Memory Analyser does not have enough heap space to open the Heap dump file.

You can solve the problem as follows:

  1. open the MemoryAnalyzer.ini file

  2. change the default -Xmx1024m to a larger size

ICR
  • 13,896
  • 4
  • 50
  • 78
codeisee
  • 1,612
  • 2
  • 11
  • 9
  • 2
    thanks for your reply,but i can't find MemoryAnalyzer.ini file,where is the location ? – Gavin Mar 22 '12 at 10:49
  • 4
    it locates in the default dir.but if you are using a eclipse plugin ,you have to enlarge the Xmx1024m of eclipse config – codeisee Mar 22 '12 at 11:20
  • 1
    but the problem is still exit when i enlarge the memory using eclipse.exe -vmargs -Xverify:none -XX:+UseParallelGC -XX:PermSize=100M -Xms256M -Xmx600M -Duser.language=en – Gavin Mar 23 '12 at 02:51
  • now i find that it can parse .hprof file when less than 100M,but not when larger than 100M – Gavin Mar 23 '12 at 03:12
  • 1
    This method doesn't work with the latest version of OS X (El Cap) and MemoryAnalzyer (1.5.0), see my answer below for a workaround. – Russell Cohen Jun 29 '16 at 20:34
  • This was really helpful. – cyphx May 07 '19 at 12:15
  • 3
    In mac , MemoryAnalyzer.ini file is in /Applications/mat.app/Contents/Eclipse folder. – Pallav Jun 02 '21 at 05:09
59

Note that on OS X, to increase the memory allocated to MAT, you need to right-click mat.app and show the package contents. The MemoryAnalyzer.ini file is under /Contents/Eclipse.

Chris H.
  • 2,204
  • 1
  • 19
  • 18
tkincher
  • 721
  • 5
  • 6
17

Solution for same issue for Memory Analyzer plugin in Eclipse in MAC OS X El Capitan.

I was facing the same issue but with the eclipse plugin and I did not have any Memory Analyzer App in Applications Folder. The solution which worked for me was:

  1. Right Click on Eclipse icon and select Show Package Content.
  2. Go to Contents>Eclipse
  3. Open Eclipse.ini
  4. Change value -Xmx1024m to -Xmx2048m
  5. Restart Eclipse
Abhishek Garg
  • 2,158
  • 1
  • 16
  • 30
  • Yes, If you have installed the MAT plugin in your eclipse you will need to increase the Memory in eclipse.ini under -Xmx as per your dump file. – Swapnil Pasarkar Dec 30 '19 at 09:19
14

On OS X 11.5 (El Cap) modifying MemoryAnalyzer.app/Contents/MacOS/MemoryAnalyzer.ini does not work! This is because it's looking for the MemoryAnalyzer.ini in a different place.

On my computer, it was looking for:

MemoryAnalyzer.app/Contents/Eclipse/MemoryAnalyzer.ini but the real .ini file was: MemoryAnalyzer.app/Contents/MacOS/MemoryAnalyzer.ini.

In order for your changes to take effect, copy the existing .ini file into the new location.

To find where MemoryAnalyzer is looking for the ini file, you can run:

sudo su
cd ...MemoryAnalyzer.app/Contents/MacOS/
dtruss ./MemoryAnalyzer 2>&1 | grep ini
Russell Cohen
  • 717
  • 4
  • 7
6

If Memory Analyser is used from Eclipse, then edit your eclipse.ini file to increase the vm argument to -Xmx1024m or higher. This worked for me. http://wiki.eclipse.org/index.php/MemoryAnalyzer/FAQ#Out_of_Memory_Error_while_Running_the_Memory_Analyzer

Goodluck
  • 61
  • 1
  • 1
5

As suggested by others, its two step simple process:-

  1. open the MemoryAnalyzer.ini file from your MAT installation directory.

  2. change the default -Xmx1024m to a larger size for e.g. if you have to analyze a 4GB heap dump then you can replace -Xmx1024m with -Xmx5g or -Xmx6g

For more details refer:- https://better-coding.com/solved-eclipse-mat-java-heap-space-error/

5

For my experience add in MemoryAnalyzer.ini, Xms and Xmx to the max as your materiel possibilities. G1GC is faster and -XX:-UseGCOverheadLimit is need because gc usage can be high and time consuming, and maybe -XX:+UseStringDeduplication is the key to consume less memory

-vmargs
-Xms8g
-Xmx8g
-XX:-UseGCOverheadLimit
-XX:+UseG1GC
-XX:+UseStringDeduplication
Mr_Thorynque
  • 1,749
  • 1
  • 20
  • 31
  • works flawlessly! To go to this file, use finder-> Macintosh hd -> Applications -> right click mat to go to contents folder -> eclipse -> MemoryAnalyzer.ini – Gaurav Dec 18 '21 at 05:07
  • This should be way higher, it significantly decreased processing time. – shibel Aug 15 '23 at 07:55
3

If you are using Mac, try running the executable inside the mat.app 'folder' with -data option, by which you can specify a writable path:

cd mat.app/Contents/MacOS
./MemoryAnalyzer -data <writable_path>
snowfox
  • 1,978
  • 1
  • 21
  • 21
0

I tried all the solutions here as well, while still getting the same error and the reason eclipse was trying to open the .hprof file as a text file due to wrong or unknown file type / editor association.

Solution: Right click on the file, select open with, then select Others, and select Eclipse Memory Analyzer.

Worked with 700MB dump, and worked with 2G dump on an eclipse heap of about 600M.

mibrahim
  • 67
  • 3
-2

An internal error has occurred. Java heap space

Ans: GO to Your Project Work space open .setting folder Delete all file of .setting folder. after you can compile now there is no error Like Heap space Enjoy :)

-3

You may reduce your application memory limit, and then again take a dump. Eclipse Memory Analyser puts dump file to memory - I suspect that your Eclipse has less memory than the limit of application.

You can also do the opposite and increase the memory limit for Eclipse, but if your application works on a server, it will be hard to match in size of memory.

wojand
  • 142
  • 5
  • MAT does _not_ have the complete `.hprof` in memory! I have memory dumps that are 3GB large which I can analyse in my 1G Eclipse instance... – Tonny Madsen Mar 22 '12 at 10:16
  • really?but when i open 200M .hprof file,there is always error. – Gavin Mar 23 '12 at 07:29
  • My solve is exactly the same as Codeisee. MAT always have problems with the analysis of large files. Look to: http://wiki.eclipse.org/index.php/MemoryAnalyzer/FAQ#Out_of_Memory_Error_while_Running_the_Memory_Analyzer. "Well, analyzing big heap dumps can also require more heap space. Give it some more memory" – wojand Mar 26 '12 at 07:22