Monday, December 10, 2012

ARC Gotcha: Unexpectedly Short Lifetimes

Mark Dalrymple (via Matt Drance):

ARC variables are released as soon as the optimizer decides that they are no longer referenced, so the compiler is free to release uicolor after fetching the CGColor. Current compiler implementations do seem to wait until the end of scope, but that’s not guaranteed.

The result is that it’s trickier to use CF and CG objects with ARC than with manual reference counting. It seems to me that Apple could fix this by marking the method as returning an interior pointer, as it does in some other APIs. Drance disagrees, but I’m not sure what makes this case more complicated.

Tags: , , , ,

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment