2011-10-12 29 views
1

我跑在我的可可應用程序自動垃圾收集的分析和接收以下錯誤信息:潛在的泄漏(使用垃圾收集時)

Potential leak (when using garbage collection) of an object allocated on line 1243 

這是什麼線1243:

self.positiveValueColor = CGColorCreateGenericRGB(0.0, 0.0, 1.0, 1.0); 

這裏是self.positiveValueColor屬性的定義:

@property (assign) CGColorRef positiveValueColor 

安儘管alyzer稍後報告了錯誤,但在下面的方法中。 「雙largestValue = 0.0」是出現在錯誤的位置,即使它引用行1243:

下面是引用整個方法:

- (void) setDefaultColors { 
    if (self.positiveValueColor == nil) { 
     self.positiveValueColor = CGColorCreateGenericRGB(0.0, 0.0, 1.0, 1.0); 
    } 

    if (self.negativeValueColor == nil) { 
     self.negativeValueColor = CGColorCreateGenericRGB(1.0, 0.0, 0.0, 1.0); 
    } 

    if (self.zeroValueColor == nil) { 
     self.zeroValueColor = CGColorGetConstantColor(kCGColorBlack); 
    } 

} 

- (BOOL) largestValueIsPositive { 
    double largestValue = 0.0; 

    if (self.pv != nil) { 
     double value = [self.pv doubleValue]; 
     if (fabs(value) > fabs(largestValue)) { 
      largestValue = value; 
     } 
    } 
    ... // method continues on 

爲什麼我收到的是分析錯誤?

- 編輯 -

謝謝,查克!這工作。以下是我用相關行代替的內容:

self.positiveValueColor = (CGColorRef)CFMakeCollectable(CGColorCreateGenericRGB(0.0, 0.0, 1.0, 1.0)); 

回答

2

CGColorRefs通常不符合垃圾回收的條件。你應該使用CFMakeCollectable()。這就是警告。

+0

完美!你是男人! –