Re: [Leopard] Debugging GC
Re: [Leopard] Debugging GC
- Subject: Re: [Leopard] Debugging GC
- From: Bill Bumgarner <email@hidden>
- Date: Mon, 29 Oct 2007 13:30:17 -0700
On Oct 29, 2007, at 12:18 PM, glenn andreas wrote:
It use to be that if you called a CFCopy style routine, you could
return the result via autorelease, something like:
- (id) getSomethingFromCarbon
{
CFFooReference cffoo = CFCopyFooWithBar(5);
return [(id)cffoo autorelease];
}
(assuming CFFooReference was one of the bridged objects).
So what is the correct idiom now?
It depends on if you are writing pure-GC or dual mode code.
In either case, you could:
- (id) getSomethingFromCarbon
{
CFFooReference cffoo = CFCopyFooWithBar(5);
return [NSMakeCollectable((id)cffoo) autorelease];
}
This will work for both GC and non-GC modes. However, if you are
writing an application, I would suggest that you turn on "GC Only"
mode. This eliminates the relatively small amount of overhead
incurred by the need for code to run in both GC or non-GC modes.
In that case, you would eliminate the -autorelease:
- (id) getSomethingFromCarbon
{
CFFooReference cffoo = CFCopyFooWithBar(5);
return NSMakeCollectable((id)cffoo);
}
You can also use CFMakeCollectable() -- same as NSMakeCollectable()
but with CF typed parameter and return value.
There is an excellent Garbage Collection Programming Guide included
with Xcode 3.0 that explains all of this and a lot more.
b.bum
_______________________________________________
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