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
40 lines
607 B
C++
40 lines
607 B
C++
/*
|
|
* Copyright (c) 2026-present, the Ladybird developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Noncopyable.h>
|
|
#include <AK/Platform.h>
|
|
#include <LibCore/Export.h>
|
|
|
|
namespace Core {
|
|
|
|
#ifdef AK_OS_MACOS
|
|
|
|
class CORE_API ScopedAutoreleasePool {
|
|
AK_MAKE_NONCOPYABLE(ScopedAutoreleasePool);
|
|
AK_MAKE_NONMOVABLE(ScopedAutoreleasePool);
|
|
|
|
public:
|
|
ScopedAutoreleasePool();
|
|
~ScopedAutoreleasePool();
|
|
|
|
private:
|
|
void* m_pool;
|
|
};
|
|
|
|
#else
|
|
|
|
class ScopedAutoreleasePool {
|
|
public:
|
|
ScopedAutoreleasePool() = default;
|
|
~ScopedAutoreleasePool() { }
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|