title: Why do I get an OutOfMemoryError when inserting 50,000 objects into HashMap?
body: <p>I am trying to insert about 50,000 objects (and therefore 50,000 keys) into a <code>java.util.HashMap&lt;java.awt.Point, Segment&gt;</code>. However, I keep getting an OutOfMemory exception. (<code>Segment</code> is my own class - very light weight - one <code>String</code> field, and 3 <code>int</code> fields).</p>
  
  <pre>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at java.util.HashMap.resize(HashMap.java:508)
      at java.util.HashMap.addEntry(HashMap.java:799)
      at java.util.HashMap.put(HashMap.java:431)
      at bus.tools.UpdateMap.putSegment(UpdateMap.java:168)</pre>
  
  <p>This seems quite ridiculous since I see that there is plenty of memory available on the machine - both in free RAM and HD space for virtual memory.</p>
  
  <p>Is it possible Java is running with some stringent memory requirements? Can I increase these?</p>
  
  <p>Is there some weird limitation with <code>HashMap</code>? Am I going to have to implement my own? Are there any other classes worth looking at?</p>
  
  <p>(I am running Java 5 under OS X 10.5 on an Intel machine with 2GB RAM.)</p>