IOS-Leaks

To detect memory leaks, we use the Leaks tool in Xcode’s own Instruments to detect

Comment “CGPathRelease” (path); this statement causes memory leaks because the class that uses C creates the object and does not manually release the object. Now use Leaks to find memory leaks in your project

#import "TriangleView.h" @implementation TriangleView (void) drawRect: (CGRect) Rect (Ref) {CGContextRef = UIGraphicsGetCurrentContext; CGMutablePathRef = CGPathCreateMutable (path); CGPathMoveToPoint (path, nil, 20, 20); CGPathAddLineToPoint (path, nil, 100, 100); CGPathAddLineToPoint (path, nil, 20; CGContextAddPath, 100) (ref, path); CGContextSetRGBFillColor (ref, 0, 1, 0, 1); CGContextDrawPath (ref, kCGPathFillStroke); / / the last one is the filling type CGPathRelease (path);} / / @end

Open the Instruments, the shortcut key, command+i, or

IOS-Leaks
image.png
IOS-Leaks
image.png

Click Leaks

IOS-Leaks
image.png

Click on the red run project in the upper left corner

You can see there is a leak of

IOS-Leaks
image.png
IOS-Leaks
image.png

That’s where the leak is.