+1  A: 

You can monitor memory usages with JConsole.

The jstat also will help.

grayger
+4  A: 

There are a number of ways to get heap dumps. Here are some I've used:

  1. -XX:+HeapDumpOnOutOfMemoryError should get you dump if you hit your OOM.
  2. Connect with VisualVM (free) and use its GUI to force a heap dump
  3. Use one of the many good commercial profilers (JProfiler, YourKit, ...)
  4. Use jmap (see below) to force a dump from a running process

If you're running Java 6, jmap should work on Windows. This might be useful if you want to dump the heap and you haven't hit your OOM. Use Windows Task Manager to find the pid of your Java app, and in a console run this:

jmap -dump:format=b,file=c:\heap.bin <pid>

In addition to VisualVM, the Eclipse Memory Analyzer (also free) can help you analyze what's eating up all the space once you've got the dump.

overthink
When I Run the Main function, an application is created in VisualVM that does not have dump functionality: you can't Heap Dump, Thread Dump, there is no Heap tab, etc.
Dave Babbitt
If -XX:+HeapDumpOnOutOfMemoryError did work, what would it look like on my system?
Dave Babbitt