Skip to content

Commit

Permalink
Fixes Objective-C objects memory leaks (#14326)
Browse files Browse the repository at this point in the history
Fixes CALayer memory leaks in file FlutterPlatformViews_Internal.mm,FlutterPlatformViews.mm

flutter/flutter#46750
  • Loading branch information
zhongwuzw authored and cbracken committed Dec 18, 2019
1 parent dda3619 commit 9c1bd8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -467,8 +467,7 @@
if (overlays_.count(overlay_id) != 0) {
return;
}
fml::scoped_nsobject<FlutterOverlayView> overlay_view(
[[[FlutterOverlayView alloc] init] retain]);
fml::scoped_nsobject<FlutterOverlayView> overlay_view([[FlutterOverlayView alloc] init]);
overlay_view.get().frame = flutter_view_.get().bounds;
overlay_view.get().autoresizingMask =
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
Expand All @@ -493,7 +492,7 @@
}
auto contentsScale = flutter_view_.get().layer.contentsScale;
fml::scoped_nsobject<FlutterOverlayView> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CGPathRef> pathRef(CGPathCreateWithRect(clipRect, nil));
CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease];
clip.path = pathRef;
self.layer.mask = clip;
CGPathRelease(pathRef);
}

- (void)clipRRect:(const SkRRect&)clipSkRRect {
Expand Down Expand Up @@ -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);
Expand All @@ -138,7 +137,7 @@ - (void)clipPath:(const SkPath&)path {
}
fml::CFRef<CGMutablePathRef> pathRef(CGPathCreateMutable());
if (path.isEmpty()) {
CAShapeLayer* clip = [[CAShapeLayer alloc] init];
CAShapeLayer* clip = [[[CAShapeLayer alloc] init] autorelease];
clip.path = pathRef;
self.layer.mask = clip;
return;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9c1bd8a

Please sign in to comment.