mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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
25 lines
467 B
Plaintext
25 lines
467 B
Plaintext
/*
|
|
* Copyright (c) 2026-present, the Ladybird developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibCore/Platform/ScopedAutoreleasePool.h>
|
|
|
|
extern "C" void* objc_autoreleasePoolPush(void);
|
|
extern "C" void objc_autoreleasePoolPop(void* pool);
|
|
|
|
namespace Core {
|
|
|
|
ScopedAutoreleasePool::ScopedAutoreleasePool()
|
|
: m_pool(objc_autoreleasePoolPush())
|
|
{
|
|
}
|
|
|
|
ScopedAutoreleasePool::~ScopedAutoreleasePool()
|
|
{
|
|
objc_autoreleasePoolPop(m_pool);
|
|
}
|
|
|
|
}
|