title: Java Heap Space Error | Doubly linked lists
body: <p>The goal of program is to create two doubly linked list, reading numbers from a file and adding them together, creating a new doubly linked list and printing the result. Running it, I am presented with the error, 
  Java lang out of memory: java heap space error</p>
  
  <p>I am relatively new to data structures and coding, and cannot figure out what is causing this error. Currently thinking that it is somewhere in my loop, creating extra nodes in an infinite loop. (Included the loop with the error, not full code).</p>
  
  <pre><code>int sum = 0;
    Digit endHead = new Digit(); //summed linked list
    Digit endCurr = endHead;
    Digit endPrev = endHead;
    while (true)
    {
        if (currOne == null &amp;&amp; currTwo == null) //ex. at the end of addition carrying the last number.
        {
            sum = sum;
        }
        else if (currOne == null)
        {
            sum = currTwo.value + sum;
        }
  
        else if (currTwo == null)
        {
            sum = currOne.value + sum;
        }
        else
        {
            sum = currOne.value + currTwo.value + sum;  
        }
  
        endCurr.value = sum % 10; //to get the number to carry over
        sum = sum / 10; //to get the ones place
  
        if (currOne == null &amp;&amp; currTwo == null &amp;&amp; sum == 0)
        {
            break;
        }
        else
        {
            endCurr.next = new Digit();
            endCurr = endCurr.next;
            endCurr.prev = endPrev;
            endPrev = endCurr;
        }  
    }
  </code></pre>