Search guides and the APICtrl K
  1. API reference
  2. Applications

leak_detector.h

A count of live objects per class, reported at exit if any are still alive.

#include <sonore/leak_detector.h>
On this page

Design notes

What it is for, next to a sanitizer

AddressSanitizer finds leaks, and finds them better: every allocation, with the stack that made it. But it runs in a sanitizer build, and a plugin's leaks show up in a HOST -- a DAW that loads the plugin, opens and closes the editor forty times and quits -- which is not built with ASan and often will not load an ASan-built plugin at all. This works in an ordinary debug build inside any host: each class that declares SONORE_LEAK_DETECTOR(ClassName) keeps an atomic count of its live instances, and when the module unloads, a count above zero is reported by name. "3 instance(s) of FilterEditor were never deleted" says which class to look at; the sanitizer then says where.

The report goes to stderr, to the debugger's output window on Windows (a host has no console), and to a handler if one is installed -- a test can install one and assert on it.

Cost

On by default in debug builds (NDEBUG not defined), nothing at all in release: the macro expands to no member, so the class's size and layout are what they would be without it. Define SONORE_CHECK_MEMORY_LEAKS to 1 or 0 to choose. Where it is on, construction and destruction are one atomic increment or decrement each -- lock-free, so an object made on the audio thread may carry one.

Types 1

template <class OwnerClass> class LeakedObjectDetector

Counts the live instances of OwnerClass. Normally added through SONORE_LEAK_DETECTOR(OwnerClass) inside the class; a member of this type is created and destroyed (and copied) with its owner.

Functions 1

Aliases 1

Macros 1

↑↓ to move↵ to openEvery public name in the headers, and every guide