Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is this a potential leak of an object?

Could someone please explain why I get the "potential leak of an object" warning here ? I don't get it. Thank you!

-(Code) drawTo:(ContextClass *) trg
{
  CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB();
  CGFloat values[4] = { getRed(colour),
                      getGreen(colour),
                      getBlue(colour), 1.0 };

  trg.storedColourRef = CGColorCreate(rgbColorspace, values);    

  CGColorSpaceRelease(rgbColorspace);

  return OK;
}    

Is it because I store the object in trg.storedColourRef ? ... which is a property in a different class:

@property (nonatomic, assign) CGColorRef storedColourRef;
like image 812
EarlGrey Avatar asked Jan 29 '26 15:01

EarlGrey


1 Answers

Yes, that's because you create Quartz color with CGColorCreate() and pass it to some external (?) object. Compiler could not find corresponding CGColorRelease() call that shall be used to destroy color object and therefore generates this warning.

like image 184
Rost Avatar answered Feb 01 '26 09:02

Rost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!