zig-toml icon indicating copy to clipboard operation
zig-toml copied to clipboard

memory leak

Open sunvim opened this issue 11 months ago • 3 comments

please see the below picture

Image

if move config code to another single code file, not in main entrypoint file, memory not leak any more.

sunvim avatar Mar 18 '25 11:03 sunvim

Could you share your config?

sam701 avatar Mar 18 '25 13:03 sam701

Could you share your config?

yes, it absolutely!

    port = 8741
    threads = 4
    workers = 2
    max_clients = 100_000
    max_body = 104857600

sunvim avatar Mar 19 '25 07:03 sunvim

hm, I'm just thinking how I could reproduce it. Any chance you can share some code that leads to that error?

sam701 avatar Mar 19 '25 07:03 sam701

I think I'm seeing the same thing if I just add std.debug.print("leaks: {}\n", .{gpa.detectLeaks()}); to the bottom of example1.zig.

bsl avatar May 21 '25 10:05 bsl

@bsl that's helpful, thanks! I can reproduce. I'll look into.

sam701 avatar May 21 '25 17:05 sam701

I think I'm seeing the same thing if I just add std.debug.print("leaks: {}\n", .{gpa.detectLeaks()}); to the bottom of example1.zig.

@bsl what I missed is that there are two defer statements in example.zig that free the memory. So std.debug.print("leaks: {}\n", .{gpa.detectLeaks()}); will definitely show some leaks because the memory hasn't been freed yet. There are no leaks if you explicitly call those deinit functions before the leak detection.

The error messages are exactly the same as @sunvim reported. I guess @sunvim had a similar setup.

I'm going to close this issue until we have further insights.

sam701 avatar May 21 '25 19:05 sam701

I'm sorry, I forgot that I needed to put the code under test in a block so the defers can actually happen. Thank you.

bsl avatar May 21 '25 22:05 bsl