title: Why my testNG test gets java.lang.OutOfMemoryError
body: <p>I create a simple testNG test, it doesn't work and throws OutOfMemoryError. I cannot find the cause.</p>
  
  <p>What I've done:</p>
  
  <p>I calculate the size of this big double array, and it's about 76MB which is less than the max heap size. I think the cause is in testNG. I'm not clear about how testNG pass the parameter (I checked the exception trace and found there was a char array copy, it confused me). I've searched a lot about "How testNG pass parameter" via google but don't get some useful info. So any one can help to point out the root cause, thank you.</p>
  
  <p>Environment:</p>
  
  <pre><code>Yosemite 10.10
  Java 1.8.0_25
  Eclipse luna 4.4.1
  -XX:MaxPermSize=256m
  -Xms40m
  -Xmx512m
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import java.util.Arrays;
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Test;
  
  public class TestNGTest {
      static int ARRAY_SIZE = 10000000;
  
      @DataProvider(name = "array to sort")
      public static Object[][] arrayProvider() {
          double[] myArray = new double[ARRAY_SIZE];
          for (int i = 0; i &lt; ARRAY_SIZE; i++) {
              myArray[i] = Math.random();
          }
          return new Object[][] { { myArray } };
      }
  
      @Test(dataProvider = "array to sort")
      public void testSort(double[] array) {
          Arrays.sort(array);
      }
  
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>FAILED: testSort
  java.lang.OutOfMemoryError: Java heap space
  at java.util.Arrays.copyOf(Arrays.java:3332)
  at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
  at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
  at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:421)
  at java.lang.StringBuilder.append(StringBuilder.java:136)
  at org.testng.remote.strprotocol.TestResultMessage.toString(TestResultMessage.java:320)
  at org.testng.remote.strprotocol.TestResultMessage.&lt;init&gt;(TestResultMessage.java:106)
  at org.testng.remote.strprotocol.TestResultMessage.&lt;init&gt;(TestResultMessage.java:124)
  at org.testng.remote.strprotocol.RemoteTestListener.onTestFailure(RemoteTestListener.java:72)
  at org.testng.internal.Invoker.runTestListeners(Invoker.java:1895)
  at org.testng.internal.Invoker.runTestListeners(Invoker.java:1879)
  at org.testng.internal.Invoker.invokeMethod(Invoker.java:778)
  at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
  at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
  at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
  at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
  at org.testng.TestRunner.privateRun(TestRunner.java:767)
  at org.testng.TestRunner.run(TestRunner.java:617)
  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:52)
  at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
  at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
  at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
  at org.testng.TestNG.run(TestNG.java:1057)
  at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
  at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
  at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
  </code></pre>