0

(PS: Please don't mark this as duplicate of a similar issue with eclipse. this is different one facing on Intellij)

My project build time is around 10 to 15 minutes using this command mvn clean package -Djacoco.skip=true -Dcobertura.skip=true -DskipClassConflictsReporter -DskipTests -P release and whenever I build my project using Intellij terminal, it will succeed first time but fails with the below error from second time. To solve this either I restart my intellij:

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 720096 bytes for Chunk::new
# An error report file with more information is saved as:
# C:\myserviceproject\hs_err_pid18800.log
#
# Compiler replay data is saved as:
# C:\myserviceproject\replay_pid18800.log

I have set 3GB as my -Xmx memory but still I face this error which is bothering me a lot. Could someone please help

enter image description here

enter image description here

JavaYouth
  • 1,536
  • 7
  • 21
  • 39
  • 1
    Well, how much memory is available in your system? How much of that is used when these crashes occur? – Hulk Aug 27 '21 at 12:00
  • Maven memory doesn't have to be included in Intellij memory indicator I guess. Did the numbers change when you are changing the memory properties? I guess the build should take similar amount of memory each time if you rerun all the tasks. – Filip Aug 27 '21 at 12:03
  • isn't this solves your problem? https://stackoverflow.com/a/22805787/16497617 – Maneesha Indrachapa Aug 27 '21 at 12:04
  • @ManeeshaIndrachapa - Well ... if "buy more memory" is a solution, yes :-) – Stephen C Aug 27 '21 at 12:11
  • My windows machine has 16GB RAM. And at the bottom right corner of Intellij (Small pic attached), I have noticed and when it crashes it would have used not more that 1000M of memory. I don't think that displays the memory used by the build process because it is always way less than 3GB always @Hulk – JavaYouth Aug 27 '21 at 12:21
  • What does the task manager say about available memory before you have the issue? – Didier L Aug 27 '21 at 12:24
  • This error means that OS system run out of resources (RAM) - that is available free memory that it could allocate to a java process. You should check where all the memory has been utilized by programs. Restarting the system may also help. Also check that you did not specify too high value in Settings (Preferences on macOS) | Build, Execution, Deployment | Compiler | Build process heap size (Mbytes). – Egor Klepikov Aug 27 '21 at 12:25
  • This happens even if I have closed all other applications to ensure memory is not consumed by other apps like outlook, MS Teams, Slack, etc.. Restarting of system will help once and the issue reoccurs after first successful build... Its annoying to restart and I feel there should be some solution for this. – JavaYouth Aug 27 '21 at 12:26
  • When you restart the IDE it most likely will fee up OS memory that has been swapped for the IDE process. The issue shows that you have a memory shortage on your system. Try allocating more RAM to your machine or try closing other programs that utilize OS memory. – Andrey Aug 27 '21 at 14:37

1 Answers1

1

You added heap to the IntelliJ JVM instance.

Instead you have to add it to the command line JVM by setting options by export JAVA_OPTS=-Xmx3g, in order to allow the standalone mvn to take advantage of it.

As alternative you can issue the one-line command JAVA_OPTS=-Xmx3g mvn <arguments>.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • Maybe yes, maybe no. Notice that it is a JVM crash not an OOME. I think the JVM has asked the OS for more memory and the OS has refused. If that is what is happening, increasing the Java max heap size won't help. – Stephen C Aug 27 '21 at 12:05
  • THe JVM can't ask more memory than the *Xmx*. Please, give it a try... – Antonio Petricca Aug 27 '21 at 12:06
  • That's not what I am saying. I think that the JVM is trying to allocate more off-heap memory, but the OS has run out of RAM / Swap space. – Stephen C Aug 27 '21 at 12:08
  • It maybe, but in that case you should monitor the system free memory/swap during maven running. Isn'it? – Antonio Petricca Aug 27 '21 at 12:17
  • Well yes. Or buy more RAM. But the point is that the >evidence< doesn't point to the problem being the -Xmx setting for maven. (And if this is a "machine too small" problem, then using `-Xmx3g` for both the IDE and Maven is going to make things worse.) – Stephen C Aug 27 '21 at 12:21
  • My windows machine has 16GB RAM. And at the bottom right corner of Intellij (Small pic attached), I have noticed and when it crashes it would have used not more that 1000M of memory. I don't think that displays the memory used by the build process because it is always way less than 3GB always – JavaYouth Aug 27 '21 at 12:23
  • This happens even if I have closed all other applications to ensure memory is not consume by other apps – JavaYouth Aug 27 '21 at 12:24
  • What happens if you run Maven from the command prompt instead of from within Intellij? – Stephen C Aug 27 '21 at 12:25
  • It will be same.. But i usually use intellij terminal to keep the resource utilization to minimum – JavaYouth Aug 27 '21 at 12:29
  • @AntonioPetricca - Do I just need to append `export JAVA_OPTS=-Xmx3g` to the mvn command i am using? – JavaYouth Aug 27 '21 at 12:34
  • When you say "it will be the same" do you mean that you have tried it and it >is< the same? – Stephen C Aug 27 '21 at 12:43
  • 1
    I added an alternative in my post. – Antonio Petricca Aug 27 '21 at 12:45