title: Which goes on the stack or heap?
body: <p>I am doing some studying and I came across a question that asks to show the correct memory diagram of the following code:</p>
  
  <pre><code>int [] d1 = new int[5];
  d1[0] = 3;
  
  Integer [] d2 = new Integer[5];
  d2[0] = new Integer(3);
  
  ArrayList d3 = new ArrayList();
  d3.add(3);
  </code></pre>
  
  <p>Here is my attempt at a memory diagram, but it may be incorrect:</p>
  
  <p><img src="https://i.stack.imgur.com/HHwYh.png" alt="enter image description here"></p>
  
  <p>I understand things like objects, instance variables, and "new" instances are all on the heap and things such as local variables and primitive types are on the stack, but I'm still confused when it comes to array types. </p>
  
  <p>Any help is appreciated.</p>