Hello Enjoying Zig for a few days now, love it so far, but have a question regarding allocators. Using v0.12.0 on osx and Ubuntu.
Reading through the docs and going through the zig guide to get started I noticed that most examples use the page_allocator by default and the testing allocator for tests. I also read that one should run without optimizations while developing to get full safety by default and be notified when I forget to deinit() or free() for example.
Now I noticed that when I use the page allocator and remove the deinit(), then use zig run ...
the program just executed normally, leaking the memory without any errors. When I switch to GPA, I get the expected leak error, but only when I check the deinit() result for .leak and @panic manually. I was under the impression from docs that this would be default behaviour for allocators without explicit optimization flags used.
Now my actual questions:
- is this expected behaviour?
- why are all examples using the page allocator?
- am I expected to write functions that take an allocator as dependency so I can switch it out in dev vs. Prod?
- is there a better way?
- Edit: forgot to mention that another option I am trying is comptime selecting the allocator I want to build in.
- what are the experiences and best practices here so far?
Note: this is not a rant, I love what zig is doing and I am genuinely interested.