I am building a toy HTML parser to learn Zig. It has no long running, calls main and exits. But I still want to make sure I am correctly allocating and handling memory for future projects, meaning I don't want to just use a page_allocator and deinit it once.
Below is a contrived example, but is not too far off what I am actually doing in my application, which is hundreds of more lines long and has nested ArrayListUnmanaged allocators to mimic a HTML DOM structure.
defer gpa.free(post.html);
As someone new to memory management, this feels like an anti-pattern having to know this stack backed struct has one heap backed field, I only realised this because of the leak detector.
- Is there a better approach to laying out and allocating this data structure?
- Do you have any general advice on how to think about this? I have read the below articles which has helped me understand how to literally use allocators, but I've not yet grokked how to deploy them properly.
https://pedropark99.github.io/zig-book/Chapters/01-memory.html
https://gencmurat.com/en/posts/using-allocators-in-zig/
https://ziglang.org/documentation/master/#Memory