use autorelease pools around main loop

Reduces memory usage considerably
This commit is contained in:
Stuart Carnie 2024-02-02 07:06:53 +11:00
parent 9adb7c7d13
commit 8f6d4eaa31
No known key found for this signature in database
GPG Key ID: 848D9C9718D78B4F
3 changed files with 26 additions and 13 deletions

View File

@ -160,6 +160,7 @@ DisplayServerMacOS::WindowID DisplayServerMacOS::_create_window(WindowMode p_mod
defer:NO];
ERR_FAIL_NULL_V_MSG(wd.window_object, INVALID_WINDOW_ID, "Can't create a window");
[wd.window_object setWindowID:window_id_counter];
[wd.window_object setReleasedWhenClosed:NO];
wd.window_view = [[GodotContentView alloc] init];
ERR_FAIL_NULL_V_MSG(wd.window_view, INVALID_WINDOW_ID, "Can't create a window view");

View File

@ -65,7 +65,9 @@ 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]);
}
if (err == ERR_HELP) { // Returned by --help and --version, so success.
return 0;
@ -73,11 +75,17 @@ int main(int argc, char **argv) {
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();
}

View File

@ -755,21 +755,25 @@ void OS_MacOS::run() {
return;
}
main_loop->initialize();
@autoreleasepool {
main_loop->initialize();
}
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));
}
} @catch (NSException *exception) {
ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String));
}
}