macOS: Stop disposing of objc classes at exit, as it causes rare crashes#1656
Open
emezeske wants to merge 1 commit into
Open
macOS: Stop disposing of objc classes at exit, as it causes rare crashes#1656emezeske wants to merge 1 commit into
emezeske wants to merge 1 commit into
Conversation
…n rare instances with no benefit.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.