-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
macOS: Use autorelease pools #87836
macOS: Use autorelease pools #87836
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,19 +65,27 @@ int main(int argc, char **argv) { | |
// We must override main when testing is enabled. | ||
TEST_MAIN_OVERRIDE | ||
|
||
err = Main::setup(argv[0], argc - first_arg, &argv[first_arg]); | ||
@autoreleasepool { | ||
err = Main::setup(argv[0], argc - first_arg, &argv[first_arg]); | ||
} | ||
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup any garbage generated on startup. The number of objects in the autorelease pool is almost nothing after this scoped pool |
||
|
||
if (err == ERR_HELP) { // Returned by --help and --version, so success. | ||
return 0; | ||
} else if (err != OK) { | ||
return 255; | ||
} | ||
|
||
if (Main::start()) { | ||
bool ok; | ||
@autoreleasepool { | ||
ok = Main::start(); | ||
} | ||
if (ok) { | ||
os.run(); // It is actually the OS that decides how to run. | ||
} | ||
|
||
Main::cleanup(); | ||
@autoreleasepool { | ||
Main::cleanup(); | ||
} | ||
|
||
return os.get_exit_code(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -755,21 +755,25 @@ | |
return; | ||
} | ||
|
||
main_loop->initialize(); | ||
@autoreleasepool { | ||
main_loop->initialize(); | ||
} | ||
Comment on lines
+758
to
+760
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of garbage is cleaned up here with a scoped autorelease pool |
||
|
||
bool quit = false; | ||
while (!quit) { | ||
@try { | ||
if (DisplayServer::get_singleton()) { | ||
DisplayServer::get_singleton()->process_events(); // Get rid of pending events. | ||
} | ||
joypad_macos->process_joypads(); | ||
@autoreleasepool { | ||
@try { | ||
if (DisplayServer::get_singleton()) { | ||
DisplayServer::get_singleton()->process_events(); // Get rid of pending events. | ||
} | ||
joypad_macos->process_joypads(); | ||
|
||
if (Main::iteration()) { | ||
quit = true; | ||
if (Main::iteration()) { | ||
quit = true; | ||
} | ||
} @catch (NSException *exception) { | ||
ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String)); | ||
} | ||
Comment on lines
+764
to
776
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is important to ensure autoreleased objects are freed after each iteration |
||
} @catch (NSException *exception) { | ||
ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String)); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With autorelease pools, objects are getting freed regularly, and this results in a crash if not set.