diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm index d3bb2e7c4f..2ad835b754 100644 --- a/src/corelib/kernel/qcore_mac.mm +++ b/src/corelib/kernel/qcore_mac.mm @@ -224,10 +224,20 @@ QT_USE_NAMESPACE QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAutoReleasePoolTracker); #endif // QT_DEBUG +// Use the direct runtime interface to manage autorelease pools, as it +// has less overhead then allocating NSAutoreleasePools, and allows for +// a future where we use ARC (where NSAutoreleasePool is not allowed). +// https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support + +extern "C" { +void *objc_autoreleasePoolPush(void); +void objc_autoreleasePoolPop(void *pool); +} + QT_BEGIN_NAMESPACE QMacAutoReleasePool::QMacAutoReleasePool() - : pool([[NSAutoreleasePool alloc] init]) + : pool(objc_autoreleasePoolPush()) { #ifdef QT_DEBUG static const bool debugAutoReleasePools = qEnvironmentVariableIsSet("QT_DARWIN_DEBUG_AUTORELEASEPOOLS"); @@ -272,10 +282,7 @@ QMacAutoReleasePool::QMacAutoReleasePool() QMacAutoReleasePool::~QMacAutoReleasePool() { - // Drain behaves the same as release, with the advantage that - // if we're ever used in a garbage-collected environment, the - // drain acts as a hint to the garbage collector to collect. - [static_cast(pool) drain]; + objc_autoreleasePoolPop(pool); } #ifndef QT_NO_DEBUG_STREAM