Vixen
02b45cc4
csharp
public static class LeakTracker

Records native and GPU resources that must be disposed by hand, so that "something is not being released" turns into a list of allocation sites instead of a memory graph that grows.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Managed memory does not need this — the GC finds it. What needs it is everything the GC cannot see: Vulkan buffers and images, native allocations, mapped ranges, file handles. A resource type calls Track in its constructor and Untrack in its Dispose; whatever is still live at shutdown was leaked, and its stack says where it came from.

Compiled out of release builds. IsSupported is a compile-time constant, so in a build without DEBUG or VIXEN_MEMORY_DEBUG the tracking methods have no body and calls to them fold away. Guard expensive argument construction with if (LeakTracker.IsSupported) and the JIT will remove the whole block.

Fields and properties (5)

  • public const bool IsSupported

    Whether this build can track at all. A compile-time constant.

  • public const long NotTracked

    The handle returned by Track when nothing was recorded.

  • public static bool IsEnabled

    Whether tracking is currently recording. Settable so a soak test or a level load can turn it off for a stretch; always where IsSupported is.

  • public static bool CaptureStackTraces

    Whether each tracked resource captures a stack trace. On by default where supported: the stack is the entire value of the report. Turn it off when the capture cost distorts what is being measured.

  • public static int LiveCount

    How many tracked resources are still live.

Methods (5)

  • public static long Track(string category, string? description = null)

    Records a resource as live.

  • public static bool Untrack(long handle)

    Records a resource as released.

  • public static LeakReport[] Snapshot()

    Everything still live, oldest first.

  • public static string FormatReport()

    Renders Snapshot as a report to log at shutdown: a count per category, then the individual entries with their stacks.

  • public static void Reset()

    Forgets every tracked resource. For tests, which must not see each other's leaks.

Used by (7)

  • ArenaAllocatorVixen.Core.Memory
  • LeakTrackerTestsVixen.Core.Tests
  • MemoryTestsVixen.Core.Memory.Tests
  • NativeArrayVixen.Core.Memory
  • MemorySnapshotVixen.Editor.Profiler
  • PlayModeControllerVixen.Editor.SceneView
  • StatisticsAndMemoryTestsVixen.Editor.Profiler.Tests