As the title says, JUCE’s disposing of objc classes at exit causes rare crashes. I did a bunch of fuzz testing and found that my standalone app crashes on exit something like 0.1-1.0% of the time due to this. I have a PR out for a simple and safe fix:
master ← emezeske:atexit-crash-fix
opened 05:31PM - 08 May 26 UTC
I have found that depending on the situation, anywhere from 0.1% to 1% of my sta… ndalone JUCE application launches end up crashing at exit due to objc_disposeClassPair() being called on a class that is still referenced.
This doesn't seem to be new. I have found several forum posts over the years that relate to this problem:
* https://forum.juce.com/t/warning-message-displayed-when-exiting-the-demo-application/20904
* https://forum.juce.com/t/warning-messages-on-startup/25389
* https://forum.juce.com/t/objc-warnings-at-exit-since-catalina-switch/40712
I noticed this causing crashes for me, and built some simple tooling to launch a basic application thousands of times, and it the crashes are complete reproducible, even for a headless app that doesn't even open a physical OS window. Exactly what is required to reproduce the crash is very hard to say; I first noticed it under MallocScribble on macOS Sequoia/Tahoe (Darwin 25.3.0), so it is likely that it requires certain memory circumstances to become a crash rather than just a warning.
The thing is: all of the ObjCClass objects that JUCE uses have static lifetime. So there's really no benefit to calling objc_disposeClassPair() -- the class will be cleaned up when the process terminates. Whatever the perceived benefit of "proper cleanup" it is outweighed by the fact that it causes crashes (or user confusion due to the warnings).
The simplest solution is to just give up on objc_disposeClassPair(). I don't see any concrete downside to this, and this change will fix crashes that I see regularly as well as questions on the forums about the warnings.