Memory usage improvements.

* Added CLI option for memory profiling and printing stats at the
  end of the run.
* Explicitly empty the streams when they are expired. This seems
  to help the GC to actually delete the memory.