From 9c1bd8aee6850716e7c7af59db57899eda46bdd9 Mon Sep 17 00:00:00 2001 From: Wu Zhong Date: Thu, 19 Dec 2019 07:32:44 +0800 Subject: [PATCH] Fixes Objective-C objects memory leaks (#14326) Fixes CALayer memory leaks in file FlutterPlatformViews_Internal.mm,FlutterPlatformViews.mm flutter/flutter#46750 --- .../ios/framework/Source/FlutterPlatformViews.mm | 7 +++---- .../framework/Source/FlutterPlatformViews_Internal.mm | 11 +++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 3371191fa3c9e..b4e4e4273602a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -253,7 +253,7 @@ // If there were not enough existing clip views, add more. while (clipIndex < number_of_clips) { ChildClippingView* clippingView = - [[ChildClippingView alloc] initWithFrame:flutter_view_.get().bounds]; + [[[ChildClippingView alloc] initWithFrame:flutter_view_.get().bounds] autorelease]; [clippingView addSubview:head]; head = clippingView; clipIndex++; @@ -467,8 +467,7 @@ if (overlays_.count(overlay_id) != 0) { return; } - fml::scoped_nsobject overlay_view( - [[[FlutterOverlayView alloc] init] retain]); + fml::scoped_nsobject overlay_view([[FlutterOverlayView alloc] init]); overlay_view.get().frame = flutter_view_.get().bounds; overlay_view.get().autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); @@ -493,7 +492,7 @@ } auto contentsScale = flutter_view_.get().layer.contentsScale; fml::scoped_nsobject overlay_view( - [[[FlutterOverlayView alloc] initWithContentsScale:contentsScale] retain]); + [[FlutterOverlayView alloc] initWithContentsScale:contentsScale]); overlay_view.get().frame = flutter_view_.get().bounds; overlay_view.get().autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index c29c7491641d1..9310fa1803f11 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -56,11 +56,10 @@ + (CGRect)getCGRectFromSkRect:(const SkRect&)clipSkRect { - (void)clipRect:(const SkRect&)clipSkRect { CGRect clipRect = [ChildClippingView getCGRectFromSkRect:clipSkRect]; - CGPathRef pathRef = CGPathCreateWithRect(clipRect, nil); - CAShapeLayer* clip = [[CAShapeLayer alloc] init]; + fml::CFRef pathRef(CGPathCreateWithRect(clipRect, nil)); + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; clip.path = pathRef; self.layer.mask = clip; - CGPathRelease(pathRef); } - (void)clipRRect:(const SkRRect&)clipSkRRect { @@ -126,7 +125,7 @@ - (void)clipRRect:(const SkRRect&)clipSkRRect { // TODO(cyanglaz): iOS does not seem to support hard edge on CAShapeLayer. It clearly stated that // the CAShaperLayer will be drawn antialiased. Need to figure out a way to do the hard edge // clipping on iOS. - CAShapeLayer* clip = [[CAShapeLayer alloc] init]; + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; clip.path = pathRef; self.layer.mask = clip; CGPathRelease(pathRef); @@ -138,7 +137,7 @@ - (void)clipPath:(const SkPath&)path { } fml::CFRef pathRef(CGPathCreateMutable()); if (path.isEmpty()) { - CAShapeLayer* clip = [[CAShapeLayer alloc] init]; + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; clip.path = pathRef; self.layer.mask = clip; return; @@ -195,7 +194,7 @@ - (void)clipPath:(const SkPath&)path { verb = iter.next(pts); } - CAShapeLayer* clip = [[CAShapeLayer alloc] init]; + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; clip.path = pathRef; self.layer.mask = clip; }