title: Java memory: Object consumes thrice the size it should
body: <p>Consider a class with a static factory method, which gets a CSV (or TSV) line as input (Variable names renamed for convenience):</p>
  
  <pre class="lang-java prettyprint-override"><code>String[] fields=StringUtils.split(tsvLine, '\t');
  return new MYObject(
      Integer.parseInt(fields[0]),
      StringUtils.strip(fields[1], "\"").intern(), // Many duplicates
      StringUtils.strip(fields[2], "\""),          // Unique
      StringUtils.strip(fields[4], "\"").intern(), // Many duplicates
      Double.parseDouble(fields[7]),
      Double.parseDouble(fields[6])); 
  </code></pre>
  
  <p>This method parses around 5 million records, from a file ~500 MB in size. In order to save memory, I save the three Strings concatenated:</p>
  
  <p>I've tried the following optimization:</p>
  
  <pre class="lang-java prettyprint-override"><code>public MyObject(int i1, String str0, String str1, String str2, 
                  double d1, double d2)
  {
  ...
  this.tsvStrings = (str0+'\t'+str1+'\t'+str2).toCharArray();
  ...
  }
  </code></pre>
  
  <p>(These are split, of course, in the appropriate getters and setters).</p>
  
  <p>The process size is still well over 1GB, although most of its contents is ignored. What's the best way to optimize this? Am I keeping unnecessary references?</p>
  
  <p><strong>EDIT</strong>: str0 and str2 have duplicates, str1 is unique.</p>