Ipad CGCOLOR释放STROKECOLOR在释放线之前导致崩溃

Ipad CGCOLOR释放STROKECOLOR在释放线之前导致崩溃,ipad,memory-management,memory-leaks,core-graphics,Ipad,Memory Management,Memory Leaks,Core Graphics,我有一个小方法,做一些核心图形绘制。今天我在XCode中使用了Clang来检测和修复一些内存泄漏。它告诉我关于“rgbColourSpace”和“fillcolor”(见下面的代码)。我想知道为什么它没有提醒我“strokeColour”,因为我也没有发布它。因此,我在方法的末尾添加了块,这将释放所有三个。奇怪的是,我的iPad应用程序会在下面所示的线路上崩溃,这实际上是在我发布“strokeColour”的线路上 // Retrieve the path for the supplied be

我有一个小方法,做一些核心图形绘制。今天我在XCode中使用了Clang来检测和修复一些内存泄漏。它告诉我关于“rgbColourSpace”和“fillcolor”(见下面的代码)。我想知道为什么它没有提醒我“strokeColour”,因为我也没有发布它。因此,我在方法的末尾添加了块,这将释放所有三个。奇怪的是,我的iPad应用程序会在下面所示的线路上崩溃,这实际上是在我发布“strokeColour”的线路上

// Retrieve the path for the supplied bedID
CGPathRef path = (CGPathRef)[self.myDictionary objectForKey:bedID];

// Save the graphics state so it can be restored later
CGContextSaveGState(self.bitmapContext);

// Initialise fill and stroke colour
CGColorRef fillColour = [UIColor whiteColor].CGColor;
CGColorRef strokeColour = [UIColor blackColor].CGColor;

// Set the stroke width
CGContextSetLineWidth(self.bitmapContext, 1.0);

// Create a CGColorSpace
CGColorSpaceRef rgbColourSpace = CGColorSpaceCreateDeviceRGB();

// Add the path to the graphics context
CGContextAddPath(self.bitmapContext, path);

// Set the fill colour...
CGContextSetFillColorWithColor(self.bitmapContext, fillColour);
// ...and stroke colour
--> CGContextSetStrokeColorWithColor(self.bitmapContext, strokeColour); // Crashes here

// Draw the path, with fill and stroke
CGContextDrawPath(self.bitmapContext, kCGPathFillStroke);

// Restore the graphics state
CGContextRestoreGState(self.bitmapContext);

// Notify the view to update itself
[self.view setNeedsDisplay];

// Release rgbColorSpace and fillColor
CGColorSpaceRelease(rgbColourSpace);
CGColorRelease(fillColour);
// CGColorRelease(*strokeColour*); -- for some reason we must not release this, or else the app crashes further up.

这让我困惑,但它是可以重复的。如果我把最后一行注释掉,一切正常;当线路激活时,它会使上面的几条线路崩溃(如上图所示)。发生什么事?这幅画不是我认为的那样吗?这一切都是以后发生的吗?如果是,为什么“FillColor”和“rgbColourSpace”没有这个问题?如有任何提示,将不胜感激。谢谢。

您不是
FillColor
strokeColour
的所有者。不要释放它们。

您不是
FillColor
strokeColour
的所有者。不要释放它们