0PricingLogin
Zig Academy · Lesson

The Testing Allocator Catches Leaks

Detect memory bugs automatically.

Memory Bugs Are Sneaky

A program can pass every value check yet still leak memory by forgetting to free it. Zig gives tests a tool to catch exactly that.

Meet testing.allocator

Inside a test you get a special allocator at std.testing.allocator. Use it anywhere your code needs to allocate heap memory.

const a = std.testing.allocator;

All lessons in this course

  1. Writing test Blocks
  2. Assertions with std.testing
  3. The Testing Allocator Catches Leaks
  4. Running and Filtering Tests
← Back to Zig Academy