Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak ? #36

Open
kculin opened this issue Feb 2, 2025 · 3 comments
Open

memory leak ? #36

kculin opened this issue Feb 2, 2025 · 3 comments

Comments

@kculin
Copy link

kculin commented Feb 2, 2025

I have been playing with customwidget.zig example and noticed that
zfltk does not execute deinit method.
Does zfltk calls deinit on custom / wrapper widgets or semething has to be done manually

@MoAlyousef
Copy link
Owner

Hello

By default in FLTK, widgets are managed by their parent widgets. So you’re not the actual owner of the widget so you you don’t need to deinit them.

@kculin
Copy link
Author

kculin commented Feb 2, 2025

Thank you, for such fast answer,

I modified

pub fn deinit(self: *Switch) void {

  • std.debug.print("Deinit\n",.{});
    self.box1.deinit();
    self.box2.deinit();
    self.label.deinit();
    app.allocator.destroy(self);
    }
    and it did not execute unless i added defer sw.deinit();
    so while fltk did managed child widgets (c++ objects), what about zig structs that run
    pub fn init(opts: Options) !*Switch {
    var self = try app.allocator.create(Switch);
    ...
    }
    and dont run
    pub fn deinit(self: *Switch) void {
    ...
    app.allocator.destroy(self);
    }

@MoAlyousef
Copy link
Owner

Yeah the Switch in the customwidget example is a custom widget which returns an allocated pointer, so that needs cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants