Sunday, February 18, 2024
HomeiOS Developmentios - Xcode analyzer is exhibiting leak for CGPathRef when it is...

ios – Xcode analyzer is exhibiting leak for CGPathRef when it is in a separate class methodology?


I’ve a category GraphicView that mainly creates a UIView that makes use of a CAShapeLayer as its default layer object:

GraphicView.h

#import <UIKit/UIKit.h>

@interface GraphicView : UIView
{
    CAShapeLayer *_shapeLayer;
}
@property(nonatomic, robust) CAShapeLayer *shapeLayer;

+ (void) loadGraphicView:(GraphicView *)graphicView withPath:(CGMutablePathRef)path;

@finish

GraphicView.m

#import "GraphicView.h"

@implementation GraphicView

- (id) initWithFrame:(CGRect)body
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.shapeLayer = (CAShapeLayer *) self.layer;
    }
    return self;
}

+ (Class)layerClass
{
    return [CAShapeLayer class];
}

+ (void) loadGraphicView:(GraphicView *)graphicView withPath:(CGMutablePathRef)path
{
    CGMutablePathRef tempPath = path;
    graphicView.shapeLayer.path = tempPath;
    CGPathRelease(tempPath);
}

@finish

Once I name loadGraphicView in one other class:

GraphicViewController.m

- (void) loadSquarePath
{
    [GraphicView loadGraphicView:self.graphicView withPath:[SquarePath newSquarePath]];
}

SquareBalloonPath.m

- (CGMutablePathRef) newSquareBalloonPath
{
    CGSize mutablePathInitialSize = [self squareBalloonPathInitialSize];
    CGMutablePathRef mutablePath = CGPathCreateMutable();
    CGPathMoveToPoint(mutablePath, NULL, 0, 0);
    CGPathAddRect(mutablePath, NULL, CGRectMake(0, 0, mutablePathInitialSize.width, mutablePathInitialSize.peak));
    CGPathCloseSubpath(mutablePath);
    return mutablePath;
}

I get an analyzer error saying “Potential leak of an object of sort ‘CGMutablePathRef'”. Nevertheless, after I transfer loadGraphicView from GraphicView to GraphicViewController:

GraphicViewController.m

- (void) loadGraphicView:(GraphicView *)graphicView withPath:(CGMutablePathRef)path
{
    CGMutablePathRef tempPath = path;
    graphicView.shapeLayer.path = tempPath;
    CGPathRelease(tempPath);
}

- (void) loadSquarePath
{
    [self loadGraphicView:self.graphicView withPath:[SquarePath newSquarePath]];
}

The analyzer error goes away! Is there one thing I’ve to inform the compiler so I can get loadGraphicView to work when it is included as a category variable inside GraphicView?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments