On Sun, Oct 26, 2008 at 7:25 AM, DKJ <[EMAIL PROTECTED]> wrote:
> I've got this in the init method of MyCALayer:
>
>        self.foregroundColor =
>                CGColorCreateGenericRGB( 1.0, 1.0, 0.9, 1.0 );

Here's your problem. CoreFoundation-style functions, of the form
<type>Create... (like CGColorCreateGenericRGB), return an object with
a reference count of 1 (just like [[<type alloc] init] in
Objective-C). You're responsible for balancing that retain count.


If you are running under garbage collection, you can do this:
    self.foregroundColor = CFMakeCollectable(CGColorCreateGenericRGB(
1.0, 1.0, 0.9, 1.0 ));

If you're not running under garbage collection, you can do this:
    CGColorRef temp = CGColorCreateGenericRGB( 1.0, 1.0, 0.9, 1.0 );
    self.foregroundColor = temp;
    CFRelease(temp);

> So I've got some questions:
>
> 1. Is there such a thing as a CGColor class? I don't see it in the
> documentation; but "CGColor" is what Instruments lists as the leaked
> objects.

Most (if not all) CoreFoundation-style objects are implicitly
Objective-C objects as well. So, while you will not find an @interface
declaration for CGColor, it exists at runtime. That said, don't rely
on the specific name of this class, as it is an implementation detail.

> 2. Are the CGColor objects being leaked when I remove MyCALayer objects from
> myArray? Should I set foregroundColor to nil when doing this?

No. As long as MyCALayer's dealloc is properly implemented (to release
foregroundColor, or set it to nil), you should never need to
explicitly do so in code that uses MyCALayer.

> 3. Are sublayers retained when added to a superlayer? I'm assuming so, since
> they're kept in an array. But then they should be released by
> removeFromSuperView, so that shouldn't cause a leak.

Correct.

-- 
Clark S. Cox III
[EMAIL PROTECTED]
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to