Files
ladybird/Libraries/LibCore/CMakeLists.txt
Andreas Kling a25fc5ad8a LibCore+LibWeb: Add ScopedAutoreleasePool and use it on macOS
On macOS, Objective-C methods frequently return autoreleased objects
that accumulate until an autorelease pool is drained. Our event loop
(Core::EventLoop) and rendering thread both lacked autorelease pools,
causing unbounded accumulation of autoreleased objects.

The rendering thread was the worst offender: every Skia flush triggers
Metal resource allocation which sets labels on GPU textures via
-[IOGPUMetalResource setLabel:], creating autoreleased CFData objects.
With ~1M+ such objects at 112 bytes each, this leaked ~121MB. Metal
command buffer objects (_MTLCommandBufferEncoderInfo, etc.) also
accumulated, adding another ~128MB.

Add Core::ScopedAutoreleasePool, a RAII wrapper around the ObjC runtime
autorelease pool (no-op on non-macOS), and drain it:
- Every event loop pump (like NSRunLoop does)
- Every compositor loop iteration on the rendering thread
2026-03-15 11:42:43 +01:00

125 lines
3.3 KiB
CMake

set(SOURCES
AddressInfoVector.cpp
ArgsParser.cpp
ConfigFile.cpp
DirIterator.cpp
Directory.cpp
DirectoryEntry.cpp
ElapsedTimer.cpp
Environment.cpp
EventLoop.cpp
EventLoopImplementation.cpp
EventReceiver.cpp
File.cpp
MappedFile.cpp
MimeData.cpp
Notifier.cpp
ReportTime.cpp
Resource.cpp
ResourceImplementation.cpp
ResourceImplementationFile.cpp
SharedVersion.cpp
SocketAddress.cpp
StandardPaths.cpp
SystemServerTakeover.cpp
ThreadEventQueue.cpp
Timer.cpp
Version.cpp
)
if (WIN32)
list(APPEND SOURCES
AnonymousBufferWindows.cpp
EventLoopImplementationWindows.cpp
LocalServerWindows.cpp
ProcessWindows.cpp
SocketWindows.cpp
SocketpairWindows.cpp
SystemWindows.cpp
TCPServerWindows.cpp
UDPServerWindows.cpp
)
else()
list(APPEND SOURCES
AnonymousBuffer.cpp
EventLoopImplementationUnix.cpp
LocalServer.cpp
Process.cpp
Socket.cpp
System.cpp
TCPServer.cpp
UDPServer.cpp
)
endif()
include(CheckIncludeFile)
check_include_file(sys/inotify.h HAVE_INOTIFY)
if (HAVE_INOTIFY)
list(APPEND SOURCES FileWatcherInotify.cpp)
else()
list(APPEND SOURCES FileWatcherUnimplemented.cpp)
endif()
# FIXME: Implement ProcessStatistics for Windows and *BSD
if (LINUX)
list(APPEND SOURCES Platform/ProcessStatisticsLinux.cpp)
elseif (APPLE AND NOT IOS)
list(APPEND SOURCES Platform/ProcessStatisticsMach.cpp)
else ()
list(APPEND SOURCES Platform/ProcessStatisticsUnimplemented.cpp)
endif()
if (LINUX OR BSD)
list(APPEND SOURCES TimeZoneWatcherUnix.cpp)
elseif (APPLE AND NOT IOS)
list(APPEND SOURCES TimeZoneWatcherMacOS.mm)
elseif (WIN32)
list(APPEND SOURCES TimeZoneWatcherWindows.cpp)
else()
list(APPEND SOURCES TimeZoneWatcherUnimplemented.cpp)
endif()
if (APPLE OR CMAKE_SYSTEM_NAME STREQUAL "GNU")
list(APPEND SOURCES MachPort.cpp)
endif()
if (APPLE)
list(APPEND SOURCES IOSurface.cpp)
list(APPEND SOURCES Platform/ScopedAutoreleasePoolMacOS.mm)
endif()
ladybird_lib(LibCore core EXPLICIT_SYMBOL_EXPORT)
target_link_libraries(LibCore PRIVATE LibUnicode LibURL Threads::Threads LibTextCodec)
if (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
# NetBSD has its shm_open and shm_unlink functions in librt so we need to link that
target_link_libraries(LibCore PRIVATE rt)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
# Solaris has socket and networking related functions in two extra libraries
target_link_libraries(LibCore PRIVATE nsl socket)
endif()
if (HAIKU)
# Haiku has networking related functions in the network library
target_link_libraries(LibCore PRIVATE network)
endif()
if (APPLE)
target_link_libraries(LibCore PUBLIC "-framework CoreFoundation")
target_link_libraries(LibCore PUBLIC "-framework CoreServices")
target_link_libraries(LibCore PUBLIC "-framework Foundation")
target_link_libraries(LibCore PUBLIC "-framework IOSurface")
endif()
if (WIN32)
target_link_libraries(LibCore PRIVATE ntdll.dll)
find_path(DIRENT_INCLUDE_DIR dirent.h REQUIRED)
target_include_directories(LibCore PRIVATE ${DIRENT_INCLUDE_DIR})
endif()
if (ANDROID)
target_link_libraries(LibCore PRIVATE log)
endif()