From 42bade91a259000ccdd97b72b82a25a9b6c0af26 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 (flutter/engine#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/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 3371191fa3..b4e4e42736 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -253,7 +253,7 @@ UIView* FlutterPlatformViewsController::ReconstructClipViewsChain(int number_of_ // 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 @@ void FlutterPlatformViewsController::EnsureOverlayInitialized( 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 @@ void FlutterPlatformViewsController::EnsureOverlayInitialized( } 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/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index c29c749164..9310fa1803 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -56,11 +56,10 @@ void ResetAnchor(CALayer* layer) { - (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 ResetAnchor(CALayer* layer) { // 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 ResetAnchor(CALayer* layer) { } 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 ResetAnchor(CALayer* layer) { verb = iter.next(pts); } - CAShapeLayer* clip = [[CAShapeLayer alloc] init]; + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; clip.path = pathRef; self.layer.mask = clip; }