title: java.lang.OutOfMemoryError: Java heap space when reading from a txt file and writing to an xlsx file
body: <p>I'm programming in order to create a tool to translate a coded .txt file in a readable .xlsx file.  (I need to work with xlsx because I'm working with more than 256 colums, so i'm using XSSFWorkbook when writing rows and colums).</p>
  
  <p>The coding part is ok.. I know it beacuse I verified it several times but when I tried to add new coding maps in the code it all ends in :</p>
  
  <pre><code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at java.util.Arrays.copyOf(Unknown Source)
      at java.io.ByteArrayOutputStream.write(Unknown Source)
      at org.apache.poi.openxml4j.opc.internal.MemoryPackagePartOutputStream.write(MemoryPackagePart OutputStream.java:88)
  at org.apache.xmlbeans.impl.store.Cursor._save(Cursor.java:590)
  at org.apache.xmlbeans.impl.store.Cursor.save(Cursor.java:2544)
  at org.apache.xmlbeans.impl.values.XmlObjectBase.save(XmlObjectBase.java:212)
  at org.apache.poi.xssf.usermodel.XSSFSheet.write(XSSFSheet.java:2480)
  at org.apache.poi.xssf.usermodel.XSSFSheet.commit(XSSFSheet.java:2439)
  at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:196)
  at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:200)
  at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:204)
  at model.Conversione.traduzioneFile(Conversione.java:241)
  at model.Main.scriviFile(Main.java:76)
  at model.Main.main(Main.java:52)
  </code></pre>
  
  <p>The error occurs after 3000/4000 lines , the memory is acting like this 
  start value:</p>
  
  <p>14443720 
  <strong><em>*</em>*</strong>:13572128 
  <strong><em>*</em>*</strong>:12078128 
  <strong><em>*</em>*</strong>:10575592
  <strong><em>*</em>*</strong>:14126224  ->new increase always lower than start value then decreasing
  <strong><em>*</em>*</strong>:12559920
  <strong><em>*</em>*</strong>:11811440
  <strong><em>*</em>*</strong>:10229128
  <strong><em>*</em>*</strong>:13751400 -> ...
  <strong><em>*</em>*</strong>:13011080</p>
  
  <p>The "coding maps" are maps generally of the type <code>HashMap&lt;Integer,Hashmap&lt;Integer,String&gt;&gt;</code>.
  (I did it like this because I can not use databases..)</p>
  
  <p>So the procedure is mainly:</p>
  
  <p>-instantiate and create the whole map at first, 
  -read line from .txt file,
  -split the line, take a token, translate it using the map and put it into rows and columns
  -wb.write(fileOutputStream fos)
  -fos.close.</p>
  
  <p>I cannot understand why that error occurs even if the maps I added are not taken into account in the translating operation...</p>
  
  <p>And why the memory quantity is so variable? (but never back to start value?)</p>
  
  <p>If i wasn't clear in some points please ask.. i don't know what to do..</p>
  
  <p>At the beginning I thought it was a buffering problem for the increasing size of .xlsx file (even if..as i said..nothing should have changed because the new maps are not used)..  </p>
  
  <p>Any hints appreciated.. </p>
  
  <p>Lucia </p>