--- a/ui/common/types.c Sun Oct 19 21:20:08 2025 +0200 +++ b/ui/common/types.c Mon Nov 10 21:52:51 2025 +0100 @@ -313,18 +313,32 @@ return d; } +static void string_destroy(UiString *s) { + if(s->value.free && s->value.ptr) { + s->value.free(s->value.ptr); + } +} + UiString* ui_string_new(UiContext *ctx, const char *name) { UiString *s = ui_malloc(ctx, sizeof(UiString)); memset(s, 0, sizeof(UiString)); + ui_set_destructor(s, (ui_destructor_func)string_destroy); if(name) { uic_reg_var(ctx, name, UI_VAR_STRING, s); } return s; } +static void text_destroy(UiText *t) { + if(t->destroy) { + t->destroy(t); + } +} + UiText* ui_text_new(UiContext *ctx, const char *name) { UiText *t = ui_malloc(ctx, sizeof(UiText)); memset(t, 0, sizeof(UiText)); + ui_set_destructor(t, (ui_destructor_func)text_destroy); if(name) { uic_reg_var(ctx, name, UI_VAR_TEXT, t); } @@ -340,9 +354,16 @@ return r; } -UIEXPORT UiGeneric* ui_generic_new(UiContext *ctx, const char *name) { +static void generic_destroy(UiGeneric *g) { + if(g->destroy) { + g->destroy(g); + } +} + +UiGeneric* ui_generic_new(UiContext *ctx, const char *name) { UiGeneric *g = ui_malloc(ctx, sizeof(UiGeneric)); memset(g, 0, sizeof(UiGeneric)); + ui_set_destructor(g, (ui_destructor_func)generic_destroy); if(name) { uic_reg_var(ctx, name, UI_VAR_GENERIC, g); }