#How can I capture leak details without panic

1 messages · Page 1 of 1 (latest)

wild orchid
#

I have my code as below, and it is notifying me if there is a leack or no, but I would like to catch the areas of memory leak without geting the program paniced or exited, is there any way to do that?

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const allocator = gpa.allocator();
    defer if (gpa.deinit() != .ok) {
        std.log.err("oh no, we've got a leak", .{});
     // CAN I ADD SOMETHING HERE TO SHOW ME MORE DEATILS ABOUT THE LEAKS IN MY CODE?
    } else {
        std.log.debug("memory managed correctly", .{});
    };
.
.
.
}
misty marsh
#

deinit does not panic or exit, but you cannot handle the logging of details yourself. the gpa uses std.log.err for that

brazen timber
#

The best I can come up with is copy paste the code for the GPA somewhere in your own code base, then modify the code so the detectLeaksInBucket and whatnot functions have more control.