I’m seeing 1MB of memory allocated every 2-3 seconds in the SDL2 audio subsystem when no work should be happening. It is definitely correlated to opening a device and leaving it open, but unfortunately, I am having a very hard time figuring out the conditions in which the leak arises; my attempts to reproduce it in a tiny program have failed. The device is paused, nothing is happening on the main thread (just busy waiting), and I don’t have any of my own threads doing anything.
Here’ a full backtrace of (what I believe is) the problematic allocation:
(lldb) bt
* thread #7, name = 'AudioQueue thread', queue = 'AQServer', stop reason = breakpoint 6.148
* frame #0: 0x0000000191114930 AudioToolbox`XAtomicAllocator::alloc()
frame #1: 0x00000001911148f8 AudioToolbox`TCustomAllocated<XAtomicAllocator, AQCommand>::operator new(unsigned long, XAtomicAllocator&) + 44
frame #2: 0x00000001911c9bdc AudioToolbox`AudioQueueObject::EnqueueBuffer(AudioQueueBuffer*, unsigned int, AudioStreamPacketDescription const*, int, int, unsigned int, AudioQueueParameterEvent*, XAudioTimeStamp const&, XAudioTimeStamp*) + 1336
frame #3: 0x00000001911df18c AudioToolbox`AudioQueueXPC_Server::EnqueueBuffer(unsigned int, std::__1::span<AQBufferCreateDestroyEvent const, 18446744073709551615ul>, unsigned int, unsigned int, unsigned int, std::__1::span<AudioStreamPacketDescription const, 18446744073709551615ul>, unsigned int, unsigned int, std::__1::span<AudioQueueParameterEvent const, 18446744073709551615ul>, XAudioTimeStampBase, bool) + 464
frame #4: 0x000000019123096c AudioToolbox`invocation function for block in AudioQueueXPC_Bridge::EnqueueBuffer(unsigned int, std::__1::span<AQBufferCreateDestroyEvent const, 18446744073709551615ul>, unsigned int, unsigned int, unsigned int, std::__1::span<AudioStreamPacketDescription const, 18446744073709551615ul>, unsigned int, unsigned int, std::__1::span<AudioQueueParameterEvent const, 18446744073709551615ul>, XAudioTimeStampBase, bool) + 132
frame #5: 0x0000000180c363e8 libdispatch.dylib`_dispatch_client_callout + 20
frame #6: 0x0000000180c45d0c libdispatch.dylib`_dispatch_sync_invoke_and_complete_recurse + 64
frame #7: 0x00000001912308b4 AudioToolbox`AudioQueueXPC_Bridge::EnqueueBuffer(unsigned int, std::__1::span<AQBufferCreateDestroyEvent const, 18446744073709551615ul>, unsigned int, unsigned int, unsigned int, std::__1::span<AudioStreamPacketDescription const, 18446744073709551615ul>, unsigned int, unsigned int, std::__1::span<AudioQueueParameterEvent const, 18446744073709551615ul>, XAudioTimeStampBase, bool) + 240
frame #8: 0x000000019118ea20 AudioToolbox`AQ::API::V2Impl::AudioQueueEnqueueBufferWithParameters(OpaqueAudioQueue*, AudioQueueBuffer*, unsigned int, AudioStreamPacketDescription const*, unsigned int, unsigned int, unsigned int, AudioQueueParameterEvent const*, AudioTimeStamp const*, AudioTimeStamp*) + 804
frame #9: 0x00000001911ae4e0 AudioToolbox`AudioQueueEnqueueBuffer + 128
frame #10: 0x0000000100a113b0 libSDL2-2.0d.0.dylib`outputCallback(inUserData=0x0000000104222be0, inAQ=0x0000000011a81000, inBuffer=0x00000001045580f0) at SDL_coreaudio.m:589:5
frame #11: 0x000000019119cfe0 AudioToolbox`AQ::API::Queue::CallOutputCallback(AudioQueueBuffer*) + 344
frame #12: 0x0000000191120bd4 AudioToolbox`AQClientCallbackMessageReader::DispatchCallbacks(void const*, unsigned long) + 288
frame #13: 0x000000019119c708 AudioToolbox`AQ::API::Queue::FetchAndDeliverPendingCallbacks() + 436
frame #14: 0x000000019119c514 AudioToolbox`(anonymous namespace)::RunLoopSourcePerform(void*) + 52
frame #15: 0x0000000180ec5eb0 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
frame #16: 0x0000000180ec5e44 CoreFoundation`__CFRunLoopDoSource0 + 176
frame #17: 0x0000000180ec5bb4 CoreFoundation`__CFRunLoopDoSources0 + 244
frame #18: 0x0000000180ec47a0 CoreFoundation`__CFRunLoopRun + 828
frame #19: 0x0000000180ec3e0c CoreFoundation`CFRunLoopRunSpecific + 608
frame #20: 0x0000000100a101d4 libSDL2-2.0d.0.dylib`audioqueue_thread(arg=0x0000000104222be0) at SDL_coreaudio.m:970:9
frame #21: 0x000000010096c120 libSDL2-2.0d.0.dylib`SDL_RunThread(thread=0x0000000104557960) at SDL_thread.c:292:18
frame #22: 0x0000000100a6aab0 libSDL2-2.0d.0.dylib`RunThread(data=0x0000000104557960) at SDL_systhread.c:76:5
frame #23: 0x0000000180de6f94 libsystem_pthread.dylib`_pthread_start + 136
Does anyone know anything about this? Is there something I could be doing wrong that would cause this?