Debug Allocator¶
#import "std/debug_allocator"
Debug allocator can be used to analyze memory usage of program and eventually analyze possible memory leaks. By DebugAllocator.init call the global context allocator is replaced by debug allocator, every following allocations are recorded and analyzed in runtime since then. Call DebugAllocator.terminate to swap default context allocator back to previous one.
Example¶
#import "std/debug_allocator"
main :: fn () s32 {
DebugAllocator.init();
defer DebugAllocator.terminate();
// leaking allocation
alloc(64);
return 0;
}
$ ./out.exe
******************* MEMORY REPORT ******************
* Allocated 64 Bytes.
* Count of allocations 1.
****************************************************
Dump memory leaks begin:
[1] - test.bl:10 (64 bytes)
Dump memory leaks end.
Note
Debug allocator is thread safe. Init and terminate must be called from main thread.