diff --git a/src/gui/platform/darwin/qmetallayer.mm b/src/gui/platform/darwin/qmetallayer.mm index e8a27a7b067..082bde95b5b 100644 --- a/src/gui/platform/darwin/qmetallayer.mm +++ b/src/gui/platform/darwin/qmetallayer.mm @@ -62,10 +62,14 @@ QT_USE_NAMESPACE - (id)nextDrawable { - // Drop the presentation block early, so that if the main thread for - // some reason doesn't handle the presentation, the block won't hold on - // to a drawable unnecessarily. - self.mainThreadPresentation = nil; + { + // Drop the presentation block early, so that if the main thread for + // some reason doesn't handle the presentation, the block won't hold on + // to a drawable unnecessarily. + QMacAutoReleasePool pool; + self.mainThreadPresentation = nil; + } + return [super nextDrawable]; } diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index c903bcd5359..51e6a19c488 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -245,11 +245,22 @@ handleExposeEvent(); - // If the expose event resulted in a secondary thread requesting that its - // drawable should be presented on the main thread with transaction, do so. - if (auto mainThreadPresentation = qtMetalLayer.mainThreadPresentation) { - mainThreadPresentation(); - qtMetalLayer.mainThreadPresentation = nil; + { + // Clearing the mainThreadPresentation below will auto-release the + // block held by the property, which in turn holds on to drawables, + // so we want to clean up as soon as possible, to prevent stalling + // when requesting new drawables. But merely referencing the block + // below for the nil-check will make another auto-released copy of + // the block, so the scope of the auto-release pool needs to include + // that check as well. + QMacAutoReleasePool pool; + + // If the expose event resulted in a secondary thread requesting that its + // drawable should be presented on the main thread with transaction, do so. + if (auto mainThreadPresentation = qtMetalLayer.mainThreadPresentation) { + mainThreadPresentation(); + qtMetalLayer.mainThreadPresentation = nil; + } } qtMetalLayer.presentsWithTransaction = presentedWithTransaction;