Toll Free Bridging and Garbage Collection
Toll Free Bridging and Garbage Collection
- Subject: Toll Free Bridging and Garbage Collection
- From: Paul Sargent <email@hidden>
- Date: Mon, 26 Nov 2007 15:51:19 +0000
I writing some code that uses IOKit, and so has to use various
CoreFoundation objects. This is going to be used in an Objective-C 2.0
program using Garbage collection, and I want to pass some of the
CFStrings that I get out of IOKit back into the rest of my code as
NSStrings.
So given that set-up:
-(NSString *) returnCFString(void) {
CFStringRef cfs = CFStringCreateWithCString(NULL, "Howdy",
kCFStringEncodingASCII);
return (NSString *)cfs;
}
The calling code is going to treat the returned string as an NSString
and not know it needs releasing, but if I release it before returning
it, it won't be valid.
Is there a way round this or do I need to create a proper NSString,
pass that back (A toll bridge if you like), and release the CFString?
--
[Obviously that code is nonsense, but it demonstrates a similar
situation. My real problem is that IOKit calls return CFStrings
created out of my control.]
_______________________________________________
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