title: Jenkins, TestNG, WebDriver: OutOfMemoryError: Java heap space
body: <p>Sometimes when I run my auto-tests (Jenkins, TestNG, WebDriver, Selenium Grid) I see following  output: </p>
  
  <pre><code>Exception in thread "Thread-1" java.lang.OutOfMemoryError: Java heap space
      at java.util.Arrays.copyOf(Arrays.java:2882)
      at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
      at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:515)
      at java.lang.StringBuffer.append(StringBuffer.java:306)
      at java.io.BufferedReader.readLine(BufferedReader.java:345)
      at java.io.BufferedReader.readLine(BufferedReader.java:362)
      at org.codehaus.plexus.util.cli.StreamPumper.run(StreamPumper.java:129)
  org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
  java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:188)
      at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:166)
      at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)
      at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:101)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
  Caused by: java.lang.OutOfMemoryError: Java heap space
      at java.util.Arrays.copyOf(Arrays.java:2882)
      at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
      at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
      at java.lang.StringBuffer.append(StringBuffer.java:224)
      at org.testng.reporters.TestHTMLReporter.generateTable(TestHTMLReporter.java:159)
      at org.testng.reporters.TestHTMLReporter.generateLog(TestHTMLReporter.java:305)
      at org.testng.reporters.TestHTMLReporter.onFinish(TestHTMLReporter.java:40)
      at org.testng.TestRunner.fireEvent(TestRunner.java:1241)
      at org.testng.TestRunner.afterRun(TestRunner.java:1040)
      at org.testng.TestRunner.run(TestRunner.java:621)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
      at org.testng.SuiteRunner.run(SuiteRunner.java:240)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1188)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1113)
      at org.testng.TestNG.run(TestNG.java:1025)
      at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:70)
      at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:160)
      at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:100)
      at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:115)
      ... 9 more
  </code></pre>
  
  <p>I can see that there are enough of disk space 2.55 GB, Windows Task Manager shows 1.39 GB in use.
  How can I avoid it? Thanks</p>