Skip to content

macOS: Stop disposing of objc classes at exit, as it causes rare crashes#1656

Open
emezeske wants to merge 1 commit into
juce-framework:masterfrom
emezeske:atexit-crash-fix
Open

macOS: Stop disposing of objc classes at exit, as it causes rare crashes#1656
emezeske wants to merge 1 commit into
juce-framework:masterfrom
emezeske:atexit-crash-fix

Conversation

@emezeske

@emezeske emezeske commented May 8, 2026

Copy link
Copy Markdown

I have found that depending on the situation, anywhere from 0.1% to 1% of my standalone 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:

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.

@juce-push-bot

Copy link
Copy Markdown
Collaborator

This pull request has been mentioned on The JUCE Forum. There might be relevant details there:

https://forum.juce.com/t/macos-disposing-of-objc-classes-at-exit-causes-rare-crashes-pr/68859/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants