The Magic of the Empty Array Literal
The line items = &[_]T{} creates a compile-time known empty array. This is special because:
- It has no runtime allocation - it’s essentially a zero-sized type
- It points to read-only memory (typically in the .rodata section)
- Zig knows not to free compile-time known memory
i.e.
pub fn deinit(self: *ArrayList) void {
if (self.allocatedSlice) |slice| {
self.allocator.free(slice);
}
}