From 4a5a4245b7f24b53847e96f1eee5445bdae537e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 20 Apr 2017 18:02:16 +0200 Subject: macOS: Add root level NSAutoreleasePool for objects autoreleased in main() Any objects directly or indirectly autoreleased in main(), before we start the event loop, will never be released, as there are no pools present yet. This includes all resources allocated during application and window setup, unless those function have local pools. Ideally that setup code would be called from within the runloop callstack, where there is a pool present, but that requires a new main/startup-API for Qt. To aid in debugging object ownership and hierarchies within Qt, we set up our own root level pool tied to QApplication, which ensures that most objects autoreleased in main() will eventually be released and have their dealloc methods called. The feature can be disabled by setting an environment variable: QT_DISABLE_ROOT_LEVEL_AUTORELEASE_POOL=1 Combined with OBJC_DEBUG_MISSING_POOLS=YES, this allows breaking on the function objc_autoreleaseNoPool to weed out codepaths in Qt that should have local pools. Change-Id: Id02e1edaaaeaa04c53862d7228e519214c99ab51 Reviewed-by: Timur Pocheptsov --- src/corelib/kernel/qcoreapplication_p.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/corelib/kernel/qcoreapplication_p.h') diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h index c646786296..da6ce1249f 100644 --- a/src/corelib/kernel/qcoreapplication_p.h +++ b/src/corelib/kernel/qcoreapplication_p.h @@ -58,6 +58,10 @@ #include "private/qobject_p.h" #endif +#ifdef Q_OS_MACOS +#include "private/qcore_mac_p.h" +#endif + QT_BEGIN_NAMESPACE typedef QList QTranslatorList; @@ -85,6 +89,10 @@ public: QString appName() const; QString appVersion() const; +#ifdef Q_OS_MACOS + QMacRootLevelAutoReleasePool autoReleasePool; +#endif + #ifdef Q_OS_DARWIN static QString infoDictionaryStringProperty(const QString &propertyName); #endif -- cgit v1.2.3