Skip to content

Generic leak checking for all allocators, and allocator-like data structures #3075

Open

Description

@IntegratedQuantum

Currently the stackAllocator and the memory pools have fairly limited leak checking, only telling you that something leaked, not where it was allocated, and even worse, I would like to remove leak checking from the memory pool to avoid the need to deinit it.

The fix for this would be relatively simple, we just create one global map that contains all the allocations and their trace, then every time an allocation happens in the relevant allocators, we just call heap.registerAllocation(ptr, len, trace) which adds an entry for ptr to the hashmap, and heap.unregisterAllocation(ptr, len) which removes the entry.

Then on application close we just print the remaining entries.

The DebugAllocator from std does something similar, but it is not usable from the outside.

Activity

  1. added
    contributor friendly
    refactor
    on May 11, 2026
  2. BoySanic commented on Jul 27, 2026

    @BoySanic
    Contributor

    I don't feel great about having to call some other function for every allocation to register it.
    I think we should create some wrapper around the allocator that handles registration for us.

    Also - how do we obtain the trace? I'm not sure whether it's intended for the programmer to just write a string there to describe where the allocation happened, or if there's some automated way of doing it properly in Zig.

  3. IntegratedQuantum commented on Jul 28, 2026

    @IntegratedQuantum
    MemberAuthor

    This would be handled by the data structures internally (GPU allocator, memory pool, stackallocator), not something you need to do manually everywhere.

    As for how to obtain the trace, just checkout Zig's DebugAllocator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyrefactor

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions