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