<story><title>The curious case of a memory leak in a Zig program</title><url>https://iamkroot.github.io/blog/zig-memleak</url></story><parent_chain><item><author>AshamedCaptain</author><text>I know absolutely nothing about Zig (but I know C) and when I read &amp;quot;FixedBufferAllocator&amp;quot; I immediately guessed what the problem would be. I can see why it is claimed as a C replacement.&lt;p&gt;I am actually kind of surprised the author spent so much time figuring it out. The name of the allocator is not that well-defined, but at least to me it hints of it being simpler rather than full-featured allocator. I would also imagine he&amp;#x27;s using this in a very anti-patternic way. One would guess the point of this would be to destroy the entire allocator on every iteration, rather than trying to free everything &amp;#x27;nicely&amp;#x27; which would be a lot of wasted work. This is a rather common pattern in a lot of &amp;quot;high-level&amp;quot; embedded development like this.</text></item></parent_chain><comment><author>laserbeam</author><text>&amp;gt; I am actually kind of surprised the author spent so much time figuring it out.&lt;p&gt;I wouldn&amp;#x27;t be. People learn different programming techniques at different times. I&amp;#x27;d actually assume quite a lot of programmers don&amp;#x27;t know what a bump allocator is and eventually run into one in the wild. Kudos for the author for successfully debugging and discovering that.&lt;p&gt;&amp;gt; One would guess the point of this would be to destroy the entire allocator on every iteration&lt;p&gt;Not necessarily every iteration, but yes, these allocators are meant to be reset to 0 at a known time, when it&amp;#x27;s safe to do so.</text></comment>
<story><title>The curious case of a memory leak in a Zig program</title><url>https://iamkroot.github.io/blog/zig-memleak</url></story><parent_chain><item><author>AshamedCaptain</author><text>I know absolutely nothing about Zig (but I know C) and when I read &amp;quot;FixedBufferAllocator&amp;quot; I immediately guessed what the problem would be. I can see why it is claimed as a C replacement.&lt;p&gt;I am actually kind of surprised the author spent so much time figuring it out. The name of the allocator is not that well-defined, but at least to me it hints of it being simpler rather than full-featured allocator. I would also imagine he&amp;#x27;s using this in a very anti-patternic way. One would guess the point of this would be to destroy the entire allocator on every iteration, rather than trying to free everything &amp;#x27;nicely&amp;#x27; which would be a lot of wasted work. This is a rather common pattern in a lot of &amp;quot;high-level&amp;quot; embedded development like this.</text></item></parent_chain><comment><author>mort96</author><text>After reading the description of the problem, I also had the thought, &amp;quot;Maybe FixedBufferAllocator is a bump allocator?&amp;quot;. So before reading further, I checked the documentation to see if I was right. Turns out .. there is no documentation for FixedBufferAllocator?&lt;p&gt;Here&amp;#x27;s the documentation page: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;ziglang.org&amp;#x2F;documentation&amp;#x2F;master&amp;#x2F;std&amp;#x2F;#A;std:heap.FixedBufferAllocator&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;ziglang.org&amp;#x2F;documentation&amp;#x2F;master&amp;#x2F;std&amp;#x2F;#A;std:heap.Fix...&lt;/a&gt;. It just lists a couple methods, most of which have the description &amp;quot;No documentation provided&amp;quot;. From those docs, it doesn&amp;#x27;t even look like there&amp;#x27;s a way to allocate memory using the FixedBufferAllocator. You might guess that it implements a bump allocator based on the fact that it only has an &amp;#x27;end_index&amp;#x27; and a slice, but wow, I feel like an allocator is the kind of thing you really want to have documented well; especially a bump allocator, and &lt;i&gt;especially&lt;/i&gt; especially a bump allocator whose name makes it sound like a general purpose allocator which happens to allocate within a fixed buffer.&lt;p&gt;I knew it was still early for Zig, but that&amp;#x27;s a bit disappointing.</text></comment>