-2

I'm trying to allocate 3 X 20485700 Bytes (total: ~600MB). If I'm writing a program in C++, I can run it without errors, But the same program (written in java) - I'm getting: java.lang.OutOfMemoryError: java heap space.

I'm using the Eclipse (Juno) - so I think that eclipse is not the problem. (Xms700m Xmx1024m)

What can I do and what is the problem?

Thanks

dave
  • 11,641
  • 5
  • 47
  • 65
user3668129
  • 4,318
  • 6
  • 45
  • 87

3 Answers3

2

Put your VM configuration parameter -Xms700m -Xmx1024m in Run Configuration of your program.

Right click on your program file (the one that contains main()), select "Run As", select "Run Configurations". On this wizard, select tab "JRE". There is a textarea as "VM Arguments". Put your VM parameters in this textarea.

Aakash
  • 2,029
  • 14
  • 22
  • I did it: openFile -vmargs -Dosgi.requiredJavaVersion=1.5 -XX:MaxPermSize=256m -Xms700m -Xmx1024m And it didnt work – user3668129 Apr 20 '15 at 08:12
  • @user3668129 This is the configuration for Eclipse, not for the program that you run inside Eclipse. – Seelenvirtuose Apr 20 '15 at 08:33
  • How to set the configuration of the program ? – user3668129 Apr 20 '15 at 08:37
  • Right click on your program file (the one that contains main()), select "Run As", select "Run Configurations". On this wizard, select tab "JRE". There is a textarea as "VM Arguments". Put your VM parameters in this textarea. – Aakash Apr 20 '15 at 08:51
1

C++ do not restrict on memory space on allocation Where as Java heap are restricted on memory it take -Xmx and -Xms as parameter and allocate the java heap for application usage. If the allocated memory space are occupied and if no more space are available for allocation then GC kicks to clear the dead objects even though after GC if java heap does not have enough space for object allocation then JVM throws OutOfMemory error to inform user/application developer then the current Xmx is not sufficient for object allocation so it help the developer to increase the Xmx based on the current usage and Application need.

Mohan Raj
  • 1,104
  • 9
  • 17
0

Java applications are allowed to use a limited amount of memory. This limit is specified during application start up. Java memory is separated into two different regions: Heap space and permgen.

The size of those regions is set during the Java Virtual Machine (JVM) launch by specifying parameters such as -Xmx and -XX:MaxPermSize. If you do not explicitly set the sizes, platform-specific defaults will be used.

Abhishek
  • 878
  • 12
  • 28