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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]