• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Toll Free Bridging and Garbage Collection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Toll Free Bridging and Garbage Collection
      • From: mmalc crawford <email@hidden>
    • Re: Toll Free Bridging and Garbage Collection
      • From: j o a r <email@hidden>
  • Prev by Date: Re: "Make This My Card" tag/switch via Contacts.syncschema ?
  • Next by Date: Re: clearing (not erasing) when drawing from a thread
  • Previous by thread: Re: "Make This My Card" tag/switch via Contacts.syncschema ?
  • Next by thread: Re: Toll Free Bridging and Garbage Collection
  • Index(es):
    • Date
    • Thread