Skip to content

Improve Mac compatibility for hsMessageBox#1766

Open
dpogue wants to merge 1 commit intoH-uru:masterfrom
dpogue:mac-messagebox
Open

Improve Mac compatibility for hsMessageBox#1766
dpogue wants to merge 1 commit intoH-uru:masterfrom
dpogue:mac-messagebox

Conversation

@dpogue
Copy link
Copy Markdown
Member

@dpogue dpogue commented Aug 26, 2025

@colincornaby Curious for your thoughts here...

The big change is moving away from blocks (which are not GCC-compatible and don't work on Mac OS X <10.6) to performSelectorOnMainThread:

The part I am least certain about is (as always) the autorelease stuff. Ugh.

@dpogue dpogue requested a review from colincornaby August 26, 2025 19:43
@dgelessus
Copy link
Copy Markdown
Contributor

I wonder if the autoreleasepool is needed at all, if the code is all linear/blocking? I think you could just do a regular release of every object at the end of the block where it's declared. (With ARC, nothing would need to be done at all.)

@colincornaby
Copy link
Copy Markdown
Contributor

I wonder if the autoreleasepool is needed at all, if the code is all linear/blocking? I think you could just do a regular release of every object at the end of the block where it's declared. (With ARC, nothing would need to be done at all.)

An autorelease pool would be needed because Cocoa may internally autorelease things. Whenever one interacts with Cocoa there should be an active autorelease pool unless the documentation supports it being unnecessary.

But what I don't know is if this code inherits the auto release pool from the main thread. But I'm ok with adding one just in case it doesn't.

NSModalResponse response = [alert runModal];
result = static_cast<hsMessageBoxResult>(response);
} else {
HSMBPresenter* presenter = [[HSMBPresenter alloc] init];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Third party Cocoa prefixes should be three letters according to the language guidelines.

HSMBPresenter* presenter = [[HSMBPresenter alloc] init];

#if !__has_feature(objc_arc)
[presenter autorelease];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to pull down the commit and take a look - so don't change anything yet... But in theory ARC would need an autorelease pool too. ARC doesn't automatically create autorelease pools. But unfortunately autorelease pool creation is different under ARC.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In its current state, this PR uses an @autoreleasepool block in ARC mode and a traditional NSAutoreleasePool in non-ARC mode. That should be enough, right?

@dpogue
Copy link
Copy Markdown
Member Author

dpogue commented Sep 1, 2025

Now I'm wondering, is there any time this file would be compiled with ARC and need to use @autoreleasepool rather than NSAutoreleasePool? I believe plClient is the only module that enables ARC

@colincornaby
Copy link
Copy Markdown
Contributor

We should check on that. It may not matter after the changes - but this code looks like it assumed ARC so it may have been leaky if ARC wasn't on.

@dpogue dpogue marked this pull request as draft September 6, 2025 03:15
@dpogue
Copy link
Copy Markdown
Member Author

dpogue commented Sep 7, 2025

Marked as draft because I rebased it on top of #1776 and am waiting for review on that

@dpogue dpogue marked this pull request as ready for review March 11, 2026 23:00
@dpogue
Copy link
Copy Markdown
Member Author

dpogue commented Mar 11, 2026

I've rebased this and gotten rid of the autorelease usage... but I am definitely not certain that I've got the retain/release stuff right

@colincornaby
Copy link
Copy Markdown
Contributor

My memory of this PR is out of date. But I'll wait for the memory issues to be addressed before looking at this again.

Co-Authored-By: dgelessus <dgelessus@users.noreply.github.com>
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.

3 participants