Re: CF autorelease?
Re: CF autorelease?
- Subject: Re: CF autorelease?
- From: Michael Ash <email@hidden>
- Date: Thu, 23 Apr 2009 21:22:53 -0400
On Thu, Apr 23, 2009 at 4:42 PM, Todd Heberlein <email@hidden> wrote:
> Many of the Cocoa object allocation methods automatically do an autorelease
> before returning the pointer to the object, so I can call something like:
>
> foo( [NSString stringWithCString: "bar" encoding: NSASCIIStringEncoding] );
>
> and then not worry about memory leakage. Is the same true with Core
> Foundation calls? For example, will
>
> foo2( CFSTR("bar") ); or
> foo2 ( CFStringCreateWithCString(NULL, "bar", kCFStringEncodingASCII) );
>
> leak memory?
>
> I am wondering if I need to do stuff like:
>
> CFStringRef tmp_str = CFSTR("bar");
> foo2(tmp_str);
> CFRelease(tmp_str);
The rules for CoreFoundation are virtually the same as for Cocoa:
1. If you obtain an object from a function which contains the word
Create or Copy, you own the object and must release it.
2. If you obtain an object from some other function, you do not own
the object and must not release it.
The major difference between CF and Cocoa memory management is that CF
has no autorelease, so there are a *lot* more functions in category #1
and a lot fewer in category #2.
Mike
_______________________________________________
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