| Summary: | Audio device leaks memory slowly over time | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Sean <seant29372> |
| Component: | audio | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | 2.0.5 | ||
| Hardware: | x86_64 | ||
| OS: | Mac OS X 10.10 | ||
|
Description
Sean
2017-05-12 16:03:55 UTC
I can't reproduce this here. My memory usage goes up by a few kilobytes for a few seconds, and then stays stable, not changing over the course of several minutes. Same result here between the SDL 2.0.5 release and the latest in revision control. It's possible macOS had a bug fixed since 10.10.5, though...? I'm on 10.12.4. --ryan. I've been playing with this... I believe the leak is inside `audioqueue_thread` in file `SDL_coreaudio.m`, on line 696: https://github.com/voidqk/sdl-audio-leak/blob/master/src/sdl-2.0.5/src/audio/coreaudio/SDL_coreaudio.m#L696 ``` while (!SDL_AtomicGet(&this->hidden->shutdown)) { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.10, 1); } ``` If I change the second parameter from `0.10` to `0.01`, then the leak rate is much higher. Here is a small sample: ``` COMMAND TIME MEM sdl-audio-leak 00:00.34 2452K+ sdl-audio-leak 00:02.99 3208K+ sdl-audio-leak 00:06.06 3796K ``` I'm going to dig through some documentation and Google searches and see if I can figure out what is going on. In fact, changing the loop to the following actually removes the leak:
```
while (!SDL_AtomicGet(&this->hidden->shutdown)) {
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, 1);
SDL_Delay(20);
}
```
Without the `SDL_Delay`, the thread will consume 100% CPU.
I don't think this is a good fix, especially since I don't understand why `CFRunLoopRunInMode` would be leaking in the first place -- but it does work on my system.
> Without the `SDL_Delay`, the thread will consume 100% CPU.
This is still baffling to me, because your program doesn't leak memory _or_ consume 100% of the CPU on my machine, even without the SDL_Delay call.
Is it possible it's a CoreAudio plugin you've installed? Some audio device I don't have?
--ryan.
I'm going to resolve this bug as WORKSFORME for now, but if some more information comes to light about what's going wrong here, definitely feel free to reopen the bug. --ryan. I just recently updated to Mac OSX 10.12.6, and the leak isn't present. So you were correct: the leak seems to be a bug in OSX 10.10.5. Changing to "FIXED" since the correct solution is to simply update the OS to the latest version. |