# java.lang.OutOfMemoryError: Java heap space on Windows VM

**URL:** <https://community.sonarsource.com/t/java-lang-outofmemoryerror-java-heap-space-on-windows-vm/42889>\
**Category:** SonarQube Server / Community Build\
**Tags:** scanner\
**Created:** [May 6, 2021, 4:21pm UTC](https://community.sonarsource.com/t/java-lang-outofmemoryerror-java-heap-space-on-windows-vm/42889 "2021-05-06T16:21:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chintalaabhi](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/chintalaabhi/32/21970_2.png) [@chintalaabhi](https://community.sonarsource.com/u/chintalaabhi)\
**Post date:** [May 6, 2021, 4:21pm UTC](https://community.sonarsource.com/t/java-lang-outofmemoryerror-java-heap-space-on-windows-vm/42889/1 "2021-05-06T16:21:45Z")

</div>

Seeing Java heap space error on SonarScanner for MSBuild. Running on windows VM and “set  
SONAR\_SCANNER\_OPTS=-Xmx8G” for 600k lines of code. Sonar server is Enterprise version.

```
17:08:38.528 INFO: 17:08:38.5287547 Building Type propagation graph
17:08:40.716 INFO: 17:08:40.7162716 Running Tarjan on 425321 nodes
17:08:41.356 INFO: 17:08:41.3569208 Tarjan found 424702 components
17:08:44.794 INFO: 17:08:44.7944569 Variable type analysis: done
17:08:44.810 INFO: 17:08:44.8102061 Building Type propagation graph
17:08:46.997 INFO: 17:08:46.9978542 Running Tarjan on 425948 nodes
17:08:51.278 INFO: 17:08:51.2788832 Tarjan found 424574 components
17:08:54.997 INFO: ------------------------------------------------------------------------
17:08:54.997 INFO: EXECUTION FAILURE
17:08:54.997 INFO: ------------------------------------------------------------------------
17:08:54.997 INFO: Total time: 1:05.376s
17:08:55.060 INFO: Final Memory: 17M/67M
17:08:55.060 ERROR: Error during SonarScanner execution
java.lang.OutOfMemoryError: Java heap space
        at java.base/java.util.Collections.singletonIterator(Collections.java:4701)
        at java.base/java.util.Collections$SingletonSet.iterator(Collections.java:4787)
        at com.sonar.security.analysis.A.A.B.<init>(na:145)
        at com.sonar.security.analysis.N.A(na:161)
        at com.sonar.security.I.execute(na:1096)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:393)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:389)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
17:08:55.060 INFO: ------------------------------------------------------------------------
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:144)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
Process returned exit code 1
The SonarQube Scanner did not complete successfully
17:08:55.122 Post-processing failed. Exit code: 1

```

Any help is appreciated.TIA

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [May 7, 2021, 8:10am UTC](https://community.sonarsource.com/t/java-lang-outofmemoryerror-java-heap-space-on-windows-vm/42889/2 "2021-05-07T08:10:04Z")

</div>

Hey there.

What version of SonarQube are you using?

---

<div class="post-metadata">

**Author:** ![galewinston](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@galewinston](https://community.sonarsource.com/u/galewinston)\
**Post date:** [June 22, 2021, 6:37am UTC](https://community.sonarsource.com/t/java-lang-outofmemoryerror-java-heap-space-on-windows-vm/42889/3 "2021-06-22T06:37:25Z")

</div>

> [@chintalaabhi](#):
>
> `java.lang.OutOfMemoryError: Java heap space`

You have to specify the heap size whenever you run your program. If you are executing on the command line, whenever you execute using "java " include a parameter: “-Xmx4g -Xmx4g” or whatever you want your heap size to be. The flag Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms specifies the initial memory allocation pool. The Xms flag has no default value, and Xmx typically has a default value of 256 MB. A common use for these flags is when you encounter a java.lang.OutOfMemoryError. If you are dealing with large data sets, then its always better to initialise your Java Collections (ex. [Java Arraylist](http://net-informations.com/java/col/arraylist.htm)) with the correct size.
