diff --git a/src/widget.zig b/src/widget.zig index 05dbb66..350dec3 100644 --- a/src/widget.zig +++ b/src/widget.zig @@ -52,14 +52,9 @@ fn Prototype(comptime Self: type) type { return self; } - /// Free the widget's resources. Will call an implementation's deinit - /// and deinit on all children. + /// Free the widget's resources. Will call an implementation's deinit function. + /// A widget must ensure to call deinit on all its children! pub fn deinit(self: *Self) void { - for (self.children()) |child| { - // TODO: call child.deinit() here - // see: https://github.com/ziglang/zig/issues/17872 - deinit(child); - } _ = statspatch.implcallOptional(self, .ptr, "deinit", void, .{self}); if (self.data.attreebutes) |*map| map.deinit(self.data.allocator); self.data.allocator.destroy(self); diff --git a/src/widgets/Box.zig b/src/widgets/Box.zig index d739bf0..57acf7a 100644 --- a/src/widgets/Box.zig +++ b/src/widgets/Box.zig @@ -50,6 +50,9 @@ pub fn init(alloc: std.mem.Allocator, direction: Direction) !*Widget { } pub fn deinit(self: *Box, selfw: *Widget) void { + for (self.children.items(.widget)) |child| { + child.deinit(); + } self.children.deinit(selfw.data.allocator); }