diff --git a/src/module.c b/src/module.c
index 25bfdf5340b97ed1be7cc843c5cc909a742eea9f..d5f3a0dc3e22fe87a4f27caea53547414bdbc7bf 100644
--- a/src/module.c
+++ b/src/module.c
@@ -348,6 +348,8 @@ static void exit_builtin_modules(void)
 
   really_clean_up_interpret();
 
+  late_exit_object();
+
   cleanup_callbacks();
   free_all_callable_blocks();
 
diff --git a/src/object.c b/src/object.c
index 7afbc3aaed56af15f4a3317fe282558898b593df..b9486033e4c7d848ea6fd9680ce6ce6370347c67 100644
--- a/src/object.c
+++ b/src/object.c
@@ -3279,7 +3279,10 @@ void exit_object(void)
     free_program(magic_types_program);
     magic_types_program=0;
   }
+}
 
+void late_exit_object(void)
+{
   exit_destroy_called_mark_hash();
 }
 
diff --git a/src/object.h b/src/object.h
index 83108e2d265d976798cf886511c3e30b87c18b33..d75d636bd9449f500506171ec46be3f79576564e 100644
--- a/src/object.h
+++ b/src/object.h
@@ -148,6 +148,7 @@ void push_magic_index(struct program *type, int inherit_no, int parent_level);
 void low_init_object(void);
 void init_object(void);
 void exit_object(void);
+void late_exit_object(void);
 void check_object_context(struct object *o,
 			  struct program *context_prog,
 			  char *current_storage);