title: Java heap space: Hashmap, ArrayList
body: <p>I would like to process a text file (about 400 MB) in order to create a recursive parent-child-structure from the data given in each line. The data have to be prepared for a top down navigation (input: parent, output: all children and sub children). E.g. of lines to be read:
  (<strong>child</strong>,id1,id2,<strong>parent</strong>,id3)</p>
  
  <p><strong>132142086</strong>;1;2;<strong>132528589</strong>;132528599<br />
  <strong>132142087</strong>;1;3;<strong>132528589</strong>;132528599<br />
  <strong>132142088</strong>;1;0;<strong>132528589</strong>;132528599<br />
  <strong>323442444</strong>;1;0;<strong>132142088</strong>;132528599<br />
  <strong>454345434</strong>;1;0;<strong>323442444</strong>;132528599<br /></p>
  
  <p>132528589: is parent of 132142086,132142087,132142088<br />
  132142088: is parent of 323442444<br />
  323442444: is parent of 454345434<br /></p>
  
  <p>Given: OS windows xp, 32bit, 2GB available Memory and -Xmx1024m
  Here is the way I prepare the data:<br /></p>
  
  <pre><code>HashMap&lt;String,ArrayList&lt;String&gt;&gt; hMap=new HashMap&lt;String,ArrayList&lt;String&gt;&gt;();
    while ((myReader = bReader.readLine()) != null) 
            {
               String [] tmpObj=myReader.split(delimiter);
                     String valuesArrayS=tmpObj[0]+";"+tmpObj[1]+";"+tmpObj[2]+";"+tmpObj[3]+";"+tmpObj[4];
                          ArrayList&lt;String&gt; valuesArray=new ArrayList&lt;String&gt;();
                          //case of same key
                          if(hMap.containsKey(tmpObj[3]))
                              {
                              valuesArray=(ArrayList&lt;String&gt;)(hMap.get(tmpObj[3])).clone();
                              }
  
                          valuesArray.add(valuesArrayS);
                          hMap.put(tmpObj[3],valuesArray);
                          tmpObj=null;
                          valuesArray=null;
                          }
  
  return hMap;
  </code></pre>
  
  <p>After then I use a recursive function:<br /> </p>
  
  <pre><code>HashMap&lt;String,ArrayList&lt;String&gt;&gt; getChildren(input parent)
  </code></pre>
  
  <p>for creating the data structure needed. The plan is to let the hMap available (read only) for more than one thread using the function getChildren.
  <br /> I tested this program with an input file of 90 MB and it seemed to work properly. However, running it with the real file with more than 380 MB lead to: <br />
  Exception in thread "main" java.lang.OutOfMemoryError: Java heap space<br />
  <strong>I need some help in memory resource management</strong></p>