Skip to content

Commit 91c813b

Browse files
zhongwuzwDmitry Lyzlov
authored andcommitted
Fixes Objective-C objects memory leaks (flutter#14326)
Fixes CALayer memory leaks in file FlutterPlatformViews_Internal.mm,FlutterPlatformViews.mm flutter/flutter#46750
1 parent e1e6ced commit 91c813b

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
// If there were not enough existing clip views, add more.
254254
while (clipIndex < number_of_clips) {
255255
ChildClippingView* clippingView =
256-
[[ChildClippingView alloc] initWithFrame:flutter_view_.get().bounds];
256+
[[[ChildClippingView alloc] initWithFrame:flutter_view_.get().bounds] autorelease];
257257
[clippingView addSubview:head];
258258
head = clippingView;
259259
clipIndex++;
@@ -463,8 +463,7 @@
463463
if (overlays_.count(overlay_id) != 0) {
464464
return;
465465
}
466-
fml::scoped_nsobject<FlutterOverlayView> overlay_view(
467-
[[[FlutterOverlayView alloc] init] retain]);
466+
fml::scoped_nsobject<FlutterOverlayView> overlay_view([[FlutterOverlayView alloc] init]);
468467
overlay_view.get().frame = flutter_view_.get().bounds;
469468
overlay_view.get().autoresizingMask =
470469
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
@@ -489,7 +488,7 @@
489488
}
490489
auto contentsScale = flutter_view_.get().layer.contentsScale;
491490
fml::scoped_nsobject<FlutterOverlayView> overlay_view(
492-
[[[FlutterOverlayView alloc] initWithContentsScale:contentsScale] retain]);
491+
[[FlutterOverlayView alloc] initWithContentsScale:contentsScale]);
493492
overlay_view.get().frame = flutter_view_.get().bounds;
494493
overlay_view.get().autoresizingMask =
495494
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ + (CGRect)getCGRectFromSkRect:(const SkRect&)clipSkRect {
5555

5656
- (void)clipRect:(const SkRect&)clipSkRect {
5757
CGRect clipRect = [ChildClippingView getCGRectFromSkRect:clipSkRect];
58-
CGPathRef pathRef = CGPathCreateWithRect(clipRect, nil);
59-
CAShapeLayer* clip = [[CAShapeLayer alloc] init];
58+
fml::CFRef<CGPathRef> pathRef(CGPathCreateWithRect(clipRect, nil));
59+
CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease];
6060
clip.path = pathRef;
6161
self.layer.mask = clip;
62-
CGPathRelease(pathRef);
6362
}
6463

6564
- (void)clipRRect:(const SkRRect&)clipSkRRect {
@@ -125,7 +124,7 @@ - (void)clipRRect:(const SkRRect&)clipSkRRect {
125124
// TODO(cyanglaz): iOS does not seem to support hard edge on CAShapeLayer. It clearly stated that
126125
// the CAShaperLayer will be drawn antialiased. Need to figure out a way to do the hard edge
127126
// clipping on iOS.
128-
CAShapeLayer* clip = [[CAShapeLayer alloc] init];
127+
CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease];
129128
clip.path = pathRef;
130129
self.layer.mask = clip;
131130
CGPathRelease(pathRef);
@@ -137,7 +136,7 @@ - (void)clipPath:(const SkPath&)path {
137136
return;
138137
}
139138
if (path.isEmpty()) {
140-
CAShapeLayer* clip = [[CAShapeLayer alloc] init];
139+
CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease];
141140
clip.path = pathRef;
142141
self.layer.mask = clip;
143142
CGPathRelease(pathRef);
@@ -195,7 +194,7 @@ - (void)clipPath:(const SkPath&)path {
195194
verb = iter.next(pts);
196195
}
197196

198-
CAShapeLayer* clip = [[CAShapeLayer alloc] init];
197+
CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease];
199198
clip.path = pathRef;
200199
self.layer.mask = clip;
201200
CGPathRelease(pathRef);

0 commit comments

Comments
 (0)