From ccf6c28b02b0d6d140000391a8d440af8a977406 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 22 Oct 2023 19:55:20 +0200 Subject: [PATCH] Add interval to Apple autoreleasepool --- .../Engine/Platform/Apple/ApplePlatform.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Platform/Apple/ApplePlatform.cpp b/Source/Engine/Platform/Apple/ApplePlatform.cpp index 523f3b561..d4348b107 100644 --- a/Source/Engine/Platform/Apple/ApplePlatform.cpp +++ b/Source/Engine/Platform/Apple/ApplePlatform.cpp @@ -48,6 +48,7 @@ CPUInfo Cpu; String UserLocale; double SecondsPerCycle; NSAutoreleasePool* AutoreleasePool = nullptr; +int32 AutoreleasePoolInterval = 0; float ApplePlatform::ScreenScale = 1.0f; @@ -359,9 +360,13 @@ bool ApplePlatform::Init() void ApplePlatform::Tick() { - // TODO: do it once every X fames - [AutoreleasePool drain]; - AutoreleasePool = [[NSAutoreleasePool alloc] init]; + AutoreleasePoolInterval++; + if (AutoreleasePoolInterval >= 60) + { + AutoreleasePoolInterval = 0; + [AutoreleasePool drain]; + AutoreleasePool = [[NSAutoreleasePool alloc] init]; + } } void ApplePlatform::BeforeExit() @@ -370,6 +375,11 @@ void ApplePlatform::BeforeExit() void ApplePlatform::Exit() { + if (AutoreleasePool) + { + [AutoreleasePool drain]; + AutoreleasePool = nullptr; + } } void ApplePlatform::SetHighDpiAwarenessEnabled(bool enable) @@ -396,9 +406,7 @@ bool ApplePlatform::GetHasFocus() if (window->IsFocused()) return true; } - - // Default to true if has no windows open - return WindowsManager::Windows.IsEmpty(); + return false; } void ApplePlatform::CreateGuid(Guid& result)