Im failing to identify where / how the mem leak is occurring. const print = std.debug.print;
T is known to the wrapping fn.
pub fn init(alloc: Allocator) []u8 {
const ptr: *T = alloc.create(T) catch unreachable; //TODO: handle better
ptr.* = T.init(alloc);
var bytes: []u8 = std.mem.asBytes(ptr);
print("\ndynamic_init --> {s}\t{}\t{}\n", .{ name, @intFromPtr(ptr), @intFromPtr(bytes.ptr) });
return bytes;
}
struct
pub const Name = struct {
value: std.ArrayList(u8),
pub fn init(alloc: Allocator) Name {
const self = Name{
.value = std.ArrayList(u8).init(alloc),
};
print("\nName.init() {}\n", .{@intFromPtr(&self)});
return self;
}
pub fn deinit(self: *Name) void {
print("\nName.deinit() {}\n", .{@intFromPtr(self)});
self.value.deinit();
}
};
log
Name.init() 49878658664
dynamic_init --> testing_structs.Name 1150146838528 1150146838528
Name.deinit() 1150146838528
[gpa] (err): memory address 0x10bca180000 leaked:
E:\projects\zig\exporation\src\zecs\TypeManager.zig:56:49: 0x7ff7b76ee3e6 in init (test.exe.obj)
const ptr: *T = alloc.create(T) catch unreachable; //TODO: handle better