Skip to content

Commit 9c1bd8a

Browse files
zhongwuzwcbracken
authored andcommitted
Fixes Objective-C objects memory leaks (flutter#14326)
Fixes CALayer memory leaks in file FlutterPlatformViews_Internal.mm,FlutterPlatformViews.mm flutter#46750
1 parent dda3619 commit 9c1bd8a

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++;
@@ -467,8 +467,7 @@
467467
if (overlays_.count(overlay_id) != 0) {
468468
return;
469469
}
470-
fml::scoped_nsobject<FlutterOverlayView> overlay_view(
471-
[[[FlutterOverlayView alloc] init] retain]);
470+
fml::scoped_nsobject<FlutterOverlayView> overlay_view([[FlutterOverlayView alloc] init]);
472471
overlay_view.get().frame = flutter_view_.get().bounds;
473472
overlay_view.get().autoresizingMask =
474473
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
@@ -493,7 +492,7 @@
493492
}
494493
auto contentsScale = flutter_view_.get().layer.contentsScale;
495494
fml::scoped_nsobject<FlutterOverlayView> overlay_view(
496-
[[[FlutterOverlayView alloc] initWithContentsScale:contentsScale] retain]);
495+
[[FlutterOverlayView alloc] initWithContentsScale:contentsScale]);
497496
overlay_view.get().frame = flutter_view_.get().bounds;
498497
overlay_view.get().autoresizingMask =
499498
(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
@@ -56,11 +56,10 @@ + (CGRect)getCGRectFromSkRect:(const SkRect&)clipSkRect {
5656

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

6665
- (void)clipRRect:(const SkRRect&)clipSkRRect {
@@ -126,7 +125,7 @@ - (void)clipRRect:(const SkRRect&)clipSkRRect {
126125
// TODO(cyanglaz): iOS does not seem to support hard edge on CAShapeLayer. It clearly stated that
127126
// the CAShaperLayer will be drawn antialiased. Need to figure out a way to do the hard edge
128127
// clipping on iOS.
129-
CAShapeLayer* clip = [[CAShapeLayer alloc] init];
128+
CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease];
130129
clip.path = pathRef;
131130
self.layer.mask = clip;
132131
CGPathRelease(pathRef);
@@ -138,7 +137,7 @@ - (void)clipPath:(const SkPath&)path {
138137
}
139138
fml::CFRef<CGMutablePathRef> pathRef(CGPathCreateMutable());
140139
if (path.isEmpty()) {
141-
CAShapeLayer* clip = [[CAShapeLayer alloc] init];
140+
CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease];
142141
clip.path = pathRef;
143142
self.layer.mask = clip;
144143
return;
@@ -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
}

0 commit comments

Comments
 (0)