title: Java Memory, Pass-by-Value, Pass-by-Reference
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/40480/is-java-pass-by-reference">Is Java pass by reference?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a question about passing by value and passing by reference in java. </p>
  
  <p>I have a "Graph" class that I wrote to display a long array of doubles as a graph, The (simplified) constructor looks like this.</p>
  
  <pre><code>private double[] Values;
  
  public Graph(double[] values) {
     Values = values;
  }
  </code></pre>
  
  <p>The array can be quite long and take up a reasonable amount of memory. </p>
  
  <p>Essentially my question is this: If I call the constructor to create a new graph, will the array "Values" be a copy of the array that's passed to it, or will it be a reference? </p>
  
  <p>In my mind, Primitives are "pass by value" and Objects are "pass by reference", which should mean that the array would be a copy. Although I'm aware that this definition is not technically correct.</p>
  
  <p>If I am correct, and the array is a copy, what would be the best way to reduce the amount of memory this class uses, and reference the array from another class?
  Would an abstract GetValues() method be a good way of achieving this?</p>
  
  <p>Thanks in advance,</p>
  
  <p>Chris.</p>