Added rehashing of id hash maps.

As a part of this added general infrastructure for fixups during gc.
Self-review, plus fixed a memory leak.