0
仪器让我发现,我在下面的代码泄漏:Objective-C - 泄漏在哪里?
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);
如果我评论这一部分,泄漏都不见了。 startPoint和endPoint是CGPoint。
负责的调用者:CGTypeCreateInstanceWithAllocator。
可能是什么问题?
但是,这是为什么?有没有用alloc的规则呢? – CristiC
如果您“创建”了颜色空间或渐变,它会在封面下创建一个c对象,这是您释放的责任。 –
您在这里处理的是CoreFoundation样式的对象,它们的内存管理规则与Cocoa有些不同,这不是Objective-C。 – omz