From c5992e95deb386912b27026277208098d9039f87 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 11 Dec 2019 18:09:53 +0800 Subject: [PATCH 1/5] Fixes Objective-C objects memory leaks --- .../ios/framework/Source/FlutterPlatformViews_Internal.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index dc91dde315463..e55350ef424ad 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -59,6 +59,7 @@ - (void)clipRect:(const SkRect&)clipSkRect { CAShapeLayer* clip = [[CAShapeLayer alloc] init]; clip.path = pathRef; self.layer.mask = clip; + [clip release]; CGPathRelease(pathRef); } @@ -128,6 +129,7 @@ - (void)clipRRect:(const SkRRect&)clipSkRRect { CAShapeLayer* clip = [[CAShapeLayer alloc] init]; clip.path = pathRef; self.layer.mask = clip; + [clip release]; CGPathRelease(pathRef); } @@ -140,6 +142,7 @@ - (void)clipPath:(const SkPath&)path { CAShapeLayer* clip = [[CAShapeLayer alloc] init]; clip.path = pathRef; self.layer.mask = clip; + [clip release]; CGPathRelease(pathRef); return; } @@ -198,6 +201,7 @@ - (void)clipPath:(const SkPath&)path { CAShapeLayer* clip = [[CAShapeLayer alloc] init]; clip.path = pathRef; self.layer.mask = clip; + [clip release]; CGPathRelease(pathRef); } From c0b1ca99a4928739ba8a3510ac69b9d90a8e72a7 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 11 Dec 2019 19:28:13 +0800 Subject: [PATCH 2/5] Using scoped_nsobject instead --- .../Source/FlutterPlatformViews_Internal.mm | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index e55350ef424ad..3db82d6fd5213 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -56,10 +56,9 @@ + (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]; - clip.path = pathRef; - self.layer.mask = clip; - [clip release]; + fml::scoped_nsobject clip([[CAShapeLayer alloc] init]); + clip.get().path = pathRef; + self.layer.mask = clip.get(); CGPathRelease(pathRef); } @@ -126,10 +125,9 @@ - (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]; - clip.path = pathRef; - self.layer.mask = clip; - [clip release]; + fml::scoped_nsobject clip([[CAShapeLayer alloc] init]); + clip.get().path = pathRef; + self.layer.mask = clip.get(); CGPathRelease(pathRef); } @@ -139,10 +137,9 @@ - (void)clipPath:(const SkPath&)path { return; } if (path.isEmpty()) { - CAShapeLayer* clip = [[CAShapeLayer alloc] init]; - clip.path = pathRef; - self.layer.mask = clip; - [clip release]; + fml::scoped_nsobject clip([[CAShapeLayer alloc] init]); + clip.get().path = pathRef; + self.layer.mask = clip.get(); CGPathRelease(pathRef); return; } @@ -198,10 +195,9 @@ - (void)clipPath:(const SkPath&)path { verb = iter.next(pts); } - CAShapeLayer* clip = [[CAShapeLayer alloc] init]; - clip.path = pathRef; - self.layer.mask = clip; - [clip release]; + fml::scoped_nsobject clip([[CAShapeLayer alloc] init]); + clip.get().path = pathRef; + self.layer.mask = clip.get(); CGPathRelease(pathRef); } From 9608051bcdc51484a638ac94d79ee46b0c7e837d Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 11 Dec 2019 23:50:55 +0800 Subject: [PATCH 3/5] Fixes memory leaks in FlutterPlatformViews --- .../darwin/ios/framework/Source/FlutterPlatformViews.mm | 7 +++---- 1 file changed, 3 insertions(+), 4 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); From 1b1be0ebd9a4e785593129d6787eecea835f2b1a Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 12 Dec 2019 11:04:17 +0800 Subject: [PATCH 4/5] Change to autorelease objs --- .../Source/FlutterPlatformViews_Internal.mm | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index 3db82d6fd5213..4f67d9715701f 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -56,9 +56,9 @@ + (CGRect)getCGRectFromSkRect:(const SkRect&)clipSkRect { - (void)clipRect:(const SkRect&)clipSkRect { CGRect clipRect = [ChildClippingView getCGRectFromSkRect:clipSkRect]; CGPathRef pathRef = CGPathCreateWithRect(clipRect, nil); - fml::scoped_nsobject clip([[CAShapeLayer alloc] init]); - clip.get().path = pathRef; - self.layer.mask = clip.get(); + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; + clip.path = pathRef; + self.layer.mask = clip; CGPathRelease(pathRef); } @@ -125,9 +125,9 @@ - (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. - fml::scoped_nsobject clip([[CAShapeLayer alloc] init]); - clip.get().path = pathRef; - self.layer.mask = clip.get(); + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; + clip.path = pathRef; + self.layer.mask = clip; CGPathRelease(pathRef); } @@ -137,9 +137,9 @@ - (void)clipPath:(const SkPath&)path { return; } if (path.isEmpty()) { - fml::scoped_nsobject clip([[CAShapeLayer alloc] init]); - clip.get().path = pathRef; - self.layer.mask = clip.get(); + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; + clip.path = pathRef; + self.layer.mask = clip; CGPathRelease(pathRef); return; } @@ -195,9 +195,9 @@ - (void)clipPath:(const SkPath&)path { verb = iter.next(pts); } - fml::scoped_nsobject clip([[CAShapeLayer alloc] init]); - clip.get().path = pathRef; - self.layer.mask = clip.get(); + CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease]; + clip.path = pathRef; + self.layer.mask = clip; CGPathRelease(pathRef); } From febad53484a97e4022d3952522269191f7a06da5 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 12 Dec 2019 11:58:05 +0800 Subject: [PATCH 5/5] Using CFRef instead --- .../ios/framework/Source/FlutterPlatformViews_Internal.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index 8a75032447a9a..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); + 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 {