title: How big is an object reference?
body: <p>What is the size that a reference in Android's Java VM consumes?</p>
  <h3>More info:</h3>
  <p>By that I mean, if we have</p>
  <pre><code>String str = &quot;Watever&quot;;
  </code></pre>
  <p>I need what <code>str</code> takes, not <code>&quot;Watever&quot;</code>. --  <code>&quot;Watever&quot;</code> is what's saved in the location to which the pointer (or the reference) that <code>str</code> is holding, is pointing to.</p>
  <p>Also, if we have</p>
  <pre><code>String str = null;
  </code></pre>
  <p>how much memory does it consume? Is it the same as the other <code>str</code>?</p>
  <p>Now, if we have:</p>
  <pre><code>Object obj[] = new object[2];
  </code></pre>
  <p>how much does <code>obj</code> consume and how much does <code>obj[1]</code> and <code>obj[2]</code> consume?</p>
  <hr />
  <p>The reason for the question is the following: (in case someone can recommend something).</p>
  <p>I'm working on an app that manages many pictures downloaded from internet.
  I started storing those pictures on a &quot;bank&quot; (that consists of a list of pictures).</p>
  <p>When displaying those pictures on a gallery, I used to search for the picture in the list (SLOW) and then, if then picture wasn't there, I used to show a temporal downloading image until the picture was downloaded.</p>
  <p>Since that happened on the UI Thread, the app became very slow, so I thought about implementing a hash table on the bank instead of the list I had.</p>
  <p>As I explained before, this search occurs in the UI Thread (and I can't change that). Because of that, collisions can become a problem if they start slowing the thread.</p>
  <p>I have read that &quot;To balance time and space efficiency, the hash table should be around half full&quot;, but that makes collisions occur half of the time (Not practical for the UI Thread). That makes me think about having a very long hash table (compared to the amount of pictures saved) and use more RAM (having less free VMHeap).</p>
  <p>Before determining the size of the hash table, I wanted to know how much memory would it consume in order not to exagerate.</p>
  <p>I know that the size of the hash table might be very small compared to the memory that the pictures might consume, but I wanted to make sure I wasn't consuming more memory than necessary.</p>
  <hr />
  <p>Before asking this question i searched, between other places, in</p>
  <p><a href="https://stackoverflow.com/questions/981073/how-big-is-an-object-reference-in-java-and-precisely-what-information-does-it-con">How big is an object reference in Java and precisely what information does it contain?</a></p>
  <p><a href="https://stackoverflow.com/questions/5350950/reference-type-size-in-java">reference type size in java</a></p>
  <p><a href="http://research.cs.vt.edu/AVresearch/hashing/hashfunc.php" rel="nofollow noreferrer">Hashing Tutorial</a></p>
  <p>(Yes, I know two of the places contradict each other, that's part of the reason for the question).</p>