This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24728|Reply: 1

[Source] Could not reserve enough space for 2097152KB object heap

[Copy link]
Posted on 7/24/2017 10:43:36 AM | | | |
Error: Could not reserve enough space for 2097152KB object heap

I started activemq and reported an error, which was caused by too much allocation, so when allocating MQTT memory, it needs to be determined by combining the server memory size (use free -g) and whether JDK supports the memory size.

JVM parameter settings

Main parameters:
-Xms: Initial memory size
-Xmx: Maximum memory size
-Xmn: Younger generation size

Use the Java -Xmx2047M -version command to see if it complies:


Solution:

Start - > Control Panel - > System - > Advanced Settings - > Environment Variables - > System Variables

New Variable:
Variable Name: _JAVA_OPTIONS   
Variable value: -Xmx1G






Previous:MySQL queries a table with no empty number of records
Next:The difference between server and client of Java's virtual machine JVM
 Landlord| Posted on 7/24/2017 10:45:37 AM |
Recently working on a program for Java. Originally, I have always liked Java's memory management, no need to worry about allocating memory, just allocate, the garbage collector will reclaim the memory for you. Now the program is developed with a large amount of data, and for the sake of speed, I am going to load all the information into memory, which will ensure a fast response. I'm still repeatedly counting the memory, thinking about my own data amount, which should be enough at the beginning (my machine has 4G memory, although Windows recognizes 3.5G, but it should be fine compared to my current data volume).

Unexpectedly, the program of the first experiment ran for a few hours and encountered an Out of Memory Exception. Looking at my own VM settings, I set -Xms512M -Xmx1024M. Without thinking about it, I directly changed it to -Xms512M -Xmx2048M, and the result was that I could not reserve enough space for object heap. The program can't get up. Only then did I realize that there was still a limit to the original maximum memory. I searched the Internet and found many articles discussing this issue. Finally, I found the most useful article on BEA's DEV2DEV forum

Here moderator YuLimin did the test and came to the conclusion:

Company JVM version Maximum memory (mega) client Maximum memory (mega) server

SUN 1.5.x                          1492                            1520

SUN 1.5.5(Linux)             2634                            2660

SUN 1.4.2                          1564                            1564

SUN 1.4.2(Linux)             1900                            1260

IBM 1.4.2(Linux)             2047                             N/A

BEA JRockit 1.5 (U3)      1909                             1902

I'm using JDK1.6.0_05 now, tested it. The biggest thing in the client state is that my JDK does not recognize the -Server parameter and cannot test the server state. Estimates are about the same.

SUN 1.6.0                          1442                           N/a

It seems that it is impossible to use large memory in Java. And the general saying is that if the memory is too large, the garbage collection time will be long. This is also understandable, generally collected when the memory is not enough, scanning 2G memory is of course much slower than 1G, and there are more memory objects, the estimated relationship is exponentially increasing.

Attached below are YuLimin's test methods and test records.

Test method: Use the java -XmxXXXXM -version command to test on the command line, and then gradually increase the value of XXXX, if it runs normally, it means that the specified memory size is available, otherwise an error message will be printed.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com