fixes several memory leaks

Now it's possible to simulate some middle-sized configuration without
eating up all the memory.