From 74db7a9495fac965e2abd433879064fab3a306f5 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 10 Aug 2020 15:43:58 +0200 Subject: Native style: fix leaks in qquickmacstyle After running the "leaks" app in Instruments, several places showed up to leak memory. This patch will add auto release pools at those places to stop that from happening. Change-Id: If7f49290fde60e71d1a40c10bc3d538df6c1da5c Reviewed-by: Mitch Curtis Reviewed-by: Timur Pocheptsov --- src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm b/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm index 6ad3be5c..6cf85f14 100644 --- a/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm +++ b/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm @@ -1903,6 +1903,7 @@ NSCell *QMacStylePrivate::cocoaCell(CocoaControl cocoaControl) const void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p, DrawRectBlock drawRectBlock) const { + QMacAutoReleasePool pool; QMacCGContext ctx(p); setupNSGraphicsContext(ctx, YES); @@ -2857,6 +2858,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai // if (QTabWidget *tabWidget = qobject_cast(opt->styleObject)) // clipTabBarFrame(opt, this, ctx); //#endif + QMacAutoReleasePool pool; CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height); CGContextScaleCTM(ctx, 1, -1); if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave @@ -3026,6 +3028,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai return cs == QStyleHelper::SizeSmall ? 0.5 : 0.0; } (); d->drawNSViewInRect(tb, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) { + QMacAutoReleasePool pool; CGContextTranslateCTM(ctx, 0, vOffset); [tb.cell drawInteriorWithFrame:rect inView:tb]; }); @@ -3080,6 +3083,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai static_cast(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel; tf.frame = opt->rect.toCGRect(); d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef, const CGRect &rect) { + QMacAutoReleasePool pool; if (!qt_mac_applicationIsInDarkMode()) { // In 'Dark' mode controls are transparent, so we do not // over-paint the (potentially custom) color in the background. @@ -3444,6 +3448,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter [pb highlight:isPressed]; pb.state = isHighlighted && !isPressed ? NSOnState : NSOffState; d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef, const CGRect &r) { + QMacAutoReleasePool pool; [pb.cell drawBezelWithFrame:r inView:pb.superview]; }); [pb highlight:NO]; @@ -3658,6 +3663,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter pb.state = (isActive && isSelected && !isPressed) ? NSOnState : NSOffState; const auto drawBezelBlock = ^(CGContextRef ctx, const CGRect &r) { + QMacAutoReleasePool pool; CGContextClipToRect(ctx, opt->rect.toCGRect()); if (!isSelected || needsInactiveHack) { // Final stage of the pressed state hack: flip NSPopupButton rendering @@ -3711,6 +3717,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter tabPixmap.fill(Qt::transparent); QPainter tabPainter(&tabPixmap); d->drawNSViewInRect(pb, frameRect, &tabPainter, ^(CGContextRef ctx, const CGRect &r) { + QMacAutoReleasePool pool; CGContextTranslateCTM(ctx, -opt->rect.left(), -opt->rect.top()); drawBezelBlock(ctx, r); }); @@ -4150,6 +4157,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::ProgressIndicator_Determinate, aquaSize); auto *pi = static_cast(d->cocoaControl(cw)); d->drawNSViewInRect(pi, rect, p, ^(CGContextRef ctx, const CGRect &rect) { + QMacAutoReleasePool pool; d->setupVerticalInvertedXform(ctx, reverse, false, rect); pi.minValue = pb->minimum; pi.maxValue = pb->maximum; @@ -4200,6 +4208,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter auto *sv = static_cast(d->cocoaControl(cw)); sv.frame = opt->rect.toCGRect(); d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef, const CGRect &rect) { + QMacAutoReleasePool pool; [sv drawDividerInRect:rect]; }); } else { @@ -5058,6 +5067,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) { + QMacAutoReleasePool pool; // Since the GC is flipped, upsideDown means *not* inverted when vertical. const bool verticalFlip = !isHorizontal && !sl->upsideDown; // FIXME: && !isSierraOrLater @@ -5224,6 +5234,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex pb.frame = frameRect.toCGRect(); [pb highlight:isPressed]; d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef, const CGRect &r) { + QMacAutoReleasePool pool; [pb.cell drawBezelWithFrame:r inView:pb.superview]; }); } else if (cw.type == QMacStylePrivate::ComboBox) { @@ -5241,6 +5252,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef, const CGRect &r) { // FIXME This is usually drawn in the control's superview, but we wouldn't get inactive look in this case + QMacAutoReleasePool pool; [cb.cell drawWithFrame:r inView:cb]; }); } @@ -5311,6 +5323,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex const auto buttonRect = proxy()->subControlRect(CC_TitleBar, titlebar, sc); d->drawNSViewInRect(wb, buttonRect, p, ^(CGContextRef, const CGRect &rect) { + QMacAutoReleasePool pool; auto *wbCell = static_cast(wb.cell); [wbCell drawWithFrame:rect inView:wb]; }); @@ -5417,6 +5430,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex pb.state = isHighlighted && !isPressed ? NSOnState : NSOffState; const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton); d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef, const CGRect &rect) { + QMacAutoReleasePool pool; [pb.cell drawBezelWithFrame:rect inView:pb]; }); } -- cgit v1.2.3