From 17ef5afa6cdc26e1586637968f1b930a97fbf757 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Fri, 9 Jan 2026 13:46:28 +0100 Subject: [PATCH] Auto-release static GDTypes at exit. This fixes "unclaimed StringName" warnings and improves engine shutdown correctness. --- core/object/class_db.cpp | 10 ++++++++++ core/object/class_db.h | 4 ++++ core/object/object.cpp | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index d574267a824..61dd09801b2 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -2420,6 +2420,7 @@ void ClassDB::cleanup_defaults() { default_values_cached.clear(); } +LocalVector ClassDB::gdtype_autorelease_pool; void ClassDB::cleanup() { //OBJTYPE_LOCK; hah not here @@ -2440,6 +2441,15 @@ void ClassDB::cleanup() { resource_base_extensions.clear(); compat_classes.clear(); native_structs.clear(); + + for (GDType **type : gdtype_autorelease_pool) { + if (!type) { + WARN_PRINT("GDType in autorelease pool was cleaned up before being auto-released. Ignoring."); + } + memdelete(*type); + *type = nullptr; + } + gdtype_autorelease_pool.clear(); } // Array to use in optional parameters on methods and the DEFVAL_ARRAY macro. diff --git a/core/object/class_db.h b/core/object/class_db.h index 82ada5480a2..9516f655df5 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -234,6 +234,10 @@ public: static Array default_array_arg; static bool is_default_array_arg(const Array &p_array); + // Types added here will be automatically cleaned up on engine shutdown. + // Only add types that aren't cleaned up in another way. + static LocalVector gdtype_autorelease_pool; + private: // Non-locking variants of get_parent_class and is_parent_class. static StringName _get_parent_class(const StringName &p_class); diff --git a/core/object/object.cpp b/core/object/object.cpp index 5f091201a75..4729eecf87d 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -2383,8 +2383,10 @@ void Object::assign_type_static(GDType **type_ptr, const char *p_name, const GDT // Assigned while we were waiting. return; } - type = memnew(GDType(super_type, StringName(p_name, true))); + type = memnew(GDType(super_type, StringName(p_name))); *type_ptr = type; + + ClassDB::gdtype_autorelease_pool.push_back(type_ptr); } Object::~Object() {