Re: Guidelines for Cocoa frameworks supporting garbage collection?
Re: Guidelines for Cocoa frameworks supporting garbage collection?
- Subject: Re: Guidelines for Cocoa frameworks supporting garbage collection?
- From: Quincey Morris <email@hidden>
- Date: Sat, 5 Jul 2008 23:45:40 -0700
On Jul 5, 2008, at 22:07, Chris Hanson wrote:
On Jul 5, 2008, at 3:52 PM, Quincey Morris wrote:
The other thing worth noting is that, when GC is enabled, any CF
object that is documented to be *returned* already autoreleased
from a frameworks function is actually returned with a reference
count of 1, so you still need to call CFMakeCollectable yourself in
that case, even though you wouldn't follow it with a call to
autorelease like you would in Chris's examples.
I don't believe this is the case. Can you give an example of a
framework method that's documented to return an autoreleased CF
object?
I would assume that the result of such a method has already had
CFMakeCollectable called on it, making doing so unnecessary.
The example I was thinking of was -[QTMovie
frameImageAtTime:withAttributes:error:], which is clearly documented
to return autoreleased objects. I know from getting all tangled up in
it that with GC on it returns 'CGImageRef's and 'CVPixelBufferRef's
with a reference count of 1.
The CVPixelBufferRef was a particular trial because CFMakeCollectable
isn't allowed on it, and there's no CVMakeCollectable AFAIK.
But it may well be true that there are no non-Cocoa functions that
return autoreleased objects, only a few Cocoa methods that return
autoreleased non-Cocoa objects.
It also occurs to me that the OP is going to have to be careful to
document the behavior of methods in *his* framework that return new CF
objects (if there are any). He'll have to decide whether to use CF
rules (retain count == 1), Cocoa rules (retain count == 1 or
autoreleased object, depending on whether the caller or the framework
is regarded as the owner of the new object), or to return an object on
which CFMakeCollectable has already been called.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden