int main(int argc, char *argv[])
 {
     struct World world;
+    world.turn = 0;        /* Turns to 1 when map and objects are initalized. */
 
     init_command_db(&world);
     set_cleanup_flag(CLEANUP_COMMAND_DB);
         {
             exit_err(1, &world, err_r);
         }
+        set_cleanup_flag(CLEANUP_MAP_OBJECTS);
         exit_err(fclose(file), &world, err_c);
         player.pos.y--;
         player.pos.x--;
+        world.turn = 1;
     }
 
     /* For non-interactive mode, try to load world state from record file. */
                 "opening file 'record' for reading.";
         err_r = "Trouble loading record file (read_uint32_bigendian() in "
                 "main()) / reading from opened file 'record'.";
-        world.turn = 1;
         if (0 == world.interactive)
         {
             file = fopen(recordfile, "r");
         }
     }
 
-
     /* Generate map from seed and, if newly generated world, start positions of
      * actors.
      */
     struct Map map = init_map();
     world.map = ↦
     set_cleanup_flag(CLEANUP_MAP);
-    if (1 == world.turn)
+    if (0 == world.turn)
     {
         player.pos = find_passable_pos(world.map);
         void * foo;
         build_map_objects(&world, foo, 3, 1 + rrand() % 3);
         foo = build_map_objects(&world, &world.item, 4, 1 + rrand() % 3);
         build_map_objects(&world, foo, 5, 1 + rrand() % 3);
+        set_cleanup_flag(CLEANUP_MAP_OBJECTS);
+        world.turn = 1;
     }
 
     /* Initialize window system and windows. */
 
 
 
 
-extern struct MapObjDef * get_map_obj_def (struct World * world, char def_id)
+extern void free_items(struct Item * item)
+{
+    if (0 != item->map_obj.next)
+    {
+        free_items((struct Item *) item->map_obj.next);
+    }
+    free(item);
+}
+
+
+
+extern void free_monsters(struct Monster * monster)
+{
+    if (0 != monster->map_obj.next)
+    {
+        free_monsters((struct Monster *) monster->map_obj.next);
+    }
+    free(monster);
+}
+
+
+
+extern struct MapObjDef * get_map_obj_def(struct World * world, char def_id)
 {
     struct MapObjDef * d = NULL;
     for (d = (struct MapObjDef *) world->monster_def;
 
                                 FILE * file);
 
 
+/* Free items / monsters in map object chain starting at "item" / "monster". */
+extern void free_items(struct Item * item);
+extern void free_monsters(struct Monster * monster);
 
 /* Get pointer to the map object definition of identifier "def_id". */
 extern struct MapObjDef * get_map_obj_def(struct World * world, char def_id);
 
         free_item_defs(world->item_def);
         free_monster_defs(world->monster_def);
     }
+    if (cleanup_flags & CLEANUP_MAP_OBJECTS)
+    {
+        free_items(world->item);
+        free_monsters(world->monster);
+    }
 }
 
 
 
     CLEANUP_KEYBINDINGS     = 0x0004,
     CLEANUP_LOG             = 0x0008,
     CLEANUP_COMMAND_DB      = 0x0010,
-    CLEANUP_MAP_OBJECT_DEFS = 0x0020,
-    CLEANUP_WIN_INFO        = 0x0040,
-    CLEANUP_WIN_LOG         = 0x0080,
-    CLEANUP_WIN_MAP         = 0x0100,
-    CLEANUP_WIN_KEYS        = 0x0200
+    CLEANUP_MAP_OBJECTS     = 0x0020,
+    CLEANUP_MAP_OBJECT_DEFS = 0x0040,
+    CLEANUP_WIN_INFO        = 0x0080,
+    CLEANUP_WIN_LOG         = 0x0100,
+    CLEANUP_WIN_MAP         = 0x0200,
+    CLEANUP_WIN_KEYS        = 0x0400
 };
 extern void set_cleanup_flag(enum cleanup_flag flag);