Reputation: 22698
Instruments shows me that I have a leak in the following code:
CGContextMoveToPoint(c, startPoint.x, self.frame.size.height - offsetYBottom);
CGContextAddLineToPoint(c, startPoint.x, startPoint.y);
CGContextAddLineToPoint(c, endPoint.x, endPoint.y);
CGContextAddLineToPoint(c, endPoint.x, self.frame.size.height - offsetYBottom);
CGContextClosePath(c);
CGGradientRef myGradient;
CGColorSpaceRef myColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 0.0/255.0, 197.0/255.0, 254.0/255.0, 1.0f, 0.0/255.0, 197.0/255.0, 254.0/255.0, 0.25f };
myColorspace = CGColorSpaceCreateDeviceRGB();
myGradient = CGGradientCreateWithColorComponents (myColorspace, components, locations, num_locations);
CGPoint myStartPoint, myEndPoint;
myStartPoint.x = self.frame.size.width / 2;
myStartPoint.y = 0.0;
myEndPoint.x = self.frame.size.width / 2;
myEndPoint.y = self.frame.size.height;
CGContextSaveGState(c);
CGContextClip(c);
CGContextDrawLinearGradient (c, myGradient, myStartPoint, myEndPoint, 0);
CGContextRestoreGState(c);
If I comment this portion, the leaks are gone. startPoint and endPoint are CGPoint.
Responsible caller: CGTypeCreateInstanceWithAllocator.
What could be the problem?
Upvotes: 0
Views: 253
Reputation: 29767
Try to release myGradient object
CGGradientRelease(myGradient);
Upvotes: 1
Reputation: 53551
Following the Create Rule, you have to release myColorspace
and myGradient
when you're done with them:
CGColorSpaceRelease(myColorspace);
CGGradientRelease(myGradient);
Upvotes: 3