Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retain exported NSRunningApplication reference to avoid autorelease #7

Closed

Conversation

donaldguy
Copy link

@donaldguy donaldguy commented Jul 28, 2021

(X-fork clone of koekeishiya#973):

Per discussion/thinking outloud in koekeishiya#967 (koekeishiya#967 (comment) ) with nod from @koekeishiya – Added explicit call to retain before returning to C++:

https://developer.apple.com/documentation/objectivec/1418956-nsobject/1571946-retain

this seems to be a better way to fix koekeishiya#920 and possibly other crashes in Monterey (and who knows, maybe even earlier); and probably should have been in 8c9bbbe in the first place

I built this (on xorpse/master) and can open and close application without any crash so far on Monterey beta 3 (21A5294g) *knock on wood*

(neither the immediate crashes I was seeing on application launch before, nor the GC-triggered crash as in koekeishiya#923 (comment) )


If this were not needed it would probably introduce a memory leak.

To check I set an lldb breakpoint at https://github.com/koekeishiya/yabai/blob/8777db43b8551e0bc4e5c55d1e15bcbed52501a1/src/workspace.m#L60

Once triggered, I found that:

(lldb) p [application retainCount]
(unsigned long long) $3 = 1

and

(lldb) p (NSObject*)[ application release]
(NSObject *) $5 = nil
(lldb) p (NSObject*)[ application release]
error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x18d284930).
The process has been returned to the state before expression evaluation.

so seems good to me

@donaldguy
Copy link
Author

further exploration: koekeishiya#973 (comment)

suggests this works on both Monterey / arm64e (where it eliminates several crashes) and Big Sur / x86_64 but may leak memory on the latter ;

there is likely a set of annotations (amongst those mentioned somewhere on https://clang.llvm.org/docs/AutomaticReferenceCounting.html ) that would create consistent behavior on the two versions/platforms, but I'm not quite sure what they are (nor what has changed/is changing in clang 13 to require this call where it previously was not needed - though I suspect it may relate to a tweak in how the word create in a method name is or is not considered special)

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.

Yabai is crashing/restarting constantly on macOS 12
1 participant