23#if JUCE_ENABLE_ALLOCATION_HOOKS
28static AllocationHooks& getAllocationHooksForThread()
30 thread_local AllocationHooks hooks;
34void notifyAllocationHooksForThread()
36 getAllocationHooksForThread().listenerList.call ([] (AllocationHooks::Listener& l)
38 l.newOrDeleteCalled();
44void*
operator new (
size_t s)
46 juce::notifyAllocationHooksForThread();
47 return std::malloc (s);
50void*
operator new[] (
size_t s)
52 juce::notifyAllocationHooksForThread();
53 return std::malloc (s);
56void operator delete (
void* p)
noexcept
58 juce::notifyAllocationHooksForThread();
62void operator delete[] (
void* p)
noexcept
64 juce::notifyAllocationHooksForThread();
68void operator delete (
void* p, size_t)
noexcept
70 juce::notifyAllocationHooksForThread();
74void operator delete[] (
void* p, size_t)
noexcept
76 juce::notifyAllocationHooksForThread();
84UnitTestAllocationChecker::UnitTestAllocationChecker (UnitTest& test)
87 getAllocationHooksForThread().addListener (
this);
90UnitTestAllocationChecker::~UnitTestAllocationChecker() noexcept
92 getAllocationHooksForThread().removeListener (
this);
93 unitTest.expectEquals ((
int) calls, 0,
"new or delete was incorrectly called while allocation checker was active");
96void UnitTestAllocationChecker::newOrDeleteCalled() noexcept { ++calls; }