diff --git a/docs/changes.md b/docs/changes.md index b2e55729e..8fe092bf0 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,8 @@ # 最新动态 +2024/10/18 + * 程序结束时自动释放事件注册名称(感谢兆坤提供补丁) + 2024/10/17 * 增加给给事件注册名称的功能(感谢兆坤提供补丁) * 完善fscript错误提示(感谢兆坤提供补丁) diff --git a/src/awtk_global.c b/src/awtk_global.c index a08a14eb8..0ad29fbcb 100644 --- a/src/awtk_global.c +++ b/src/awtk_global.c @@ -36,6 +36,7 @@ #include "base/window_manager.h" #include "base/widget_factory.h" #include "base/assets_manager.h" +#include "base/events.h" #include "fscript_ext/fscript_ext.h" #ifdef FSCRIPT_WITH_WIDGET #include "fscript_ext/fscript_widget.h" @@ -432,6 +433,9 @@ ret_t tk_deinit_internal(void) { #ifndef WITHOUT_FSCRIPT fscript_global_deinit(); #endif + + event_clear_custom_name(); + tk_semaphore_destroy(s_clear_cache_semaphore); #ifdef WITH_SOCKET diff --git a/src/base/events.c b/src/base/events.c index 04b115c9e..fbed5a2de 100644 --- a/src/base/events.c +++ b/src/base/events.c @@ -45,17 +45,16 @@ ret_t event_unregister_custom_name(const char* name) { if (s_custom_event_names != NULL) { ret = tk_object_remove_prop(s_custom_event_names, name); - if (RET_OK == ret) { - int32_t size = tk_object_get_prop_int(s_custom_event_names, TK_OBJECT_PROP_SIZE, 0); - if (0 == size) { - TK_OBJECT_UNREF(s_custom_event_names); - } - } } return ret; } +ret_t event_clear_custom_name(void) { + TK_OBJECT_UNREF(s_custom_event_names); + return RET_OK; +} + static inline int32_t event_get_custom_name(const char* name) { if (s_custom_event_names == NULL) { return EVT_NONE; diff --git a/src/base/events.h b/src/base/events.h index 3c3d6a1bf..14b53eb42 100644 --- a/src/base/events.h +++ b/src/base/events.h @@ -1393,6 +1393,9 @@ ret_t event_register_custom_name(int32_t event_type, const char* name); */ ret_t event_unregister_custom_name(const char* name); +/* private */ +ret_t event_clear_custom_name(void); + #define STR_ON_EVENT_PREFIX "on:" #define STR_GLOBAL_EVENT_PREFIX "global" #define STR_GLOBAL_VARS_CHANGED "global_vars_changed"