Pre-calculate map size

Attempt to address severe memory leak.