3 ms·
C++ leak trackers are surprisingly easy to implement. You create a custom allocator that has a per-type pointer to a pair of static ints (one for allocation co
by hedora 4y ago
C++ leak trackers are surprisingly easy to implement. You create a custom allocator that has a per-type pointer to a pair of static ints (one for allocation count, one for total size).
When the allocator is statically instantiated, it adds itself to a global list.
Periodically (and at shutdown) log the top N heavy hitter allocations. In testing, assert there are no outstanding allocations in a static destructor.
The overhead of this is a couple of increments / decrements per allocation / free, so you can probably leave it on in production builds.
- throwaway2037 4y agoDo you have an open source library or reference code to share? It sounds like a good idea.