• 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
Garbage Collection Docs Puzzle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Garbage Collection Docs Puzzle


  • Subject: Garbage Collection Docs Puzzle
  • From: Robert Clair <email@hidden>
  • Date: Mon, 25 Jan 2010 16:49:32 -0500

The garbage collection docs section on the interior pointer issue shows this example:

NSData *myData = [someObject getMyData];
[myData retain];
const uint8_t *bytes = [myData bytes];
NSUInteger offset = 0, length = [myData length];

while (offset < length) {
  // bytes remains valid until next message sent to myData
}
[myData release];

What's with the retain and release? I understand the issue of keeping myData alive until you're finished with the interior pointer, but why [myData release]?   Is the release enough to keep myData alive even thought its dispatch is short circuited under GC? And the retain is there to balance the release in case someone executes under managed memory? Or did somebody mean CFRetain and CFRelease?
It seems that [myData self] or [myData class] or some other harmless (return value discarded) non-sequitor might be less confusing. It would point out that this is an issue that is being worked around  and not an ordinary part of memory management.
...Bob



_______________________________________________

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: Garbage Collection Docs Puzzle
      • From: "Sean McBride" <email@hidden>
    • Re: Garbage Collection Docs Puzzle
      • From: Dave Keck <email@hidden>
  • Prev by Date: Re: CALayer maybe silly question
  • Next by Date: How to detect no internet connection?
  • Previous by thread: NSPopUpButtonCell Update Smashes Focus Ring of Adjacent NSTableView: 10.4 vs. 10.5/10.6
  • Next by thread: Re: Garbage Collection Docs Puzzle
  • Index(es):
    • Date
    • Thread