Re: Garbage collector vs variable lifetime
Re: Garbage collector vs variable lifetime
- Subject: Re: Garbage collector vs variable lifetime
- From: Ricky Sharp <email@hidden>
- Date: Fri, 6 Jun 2008 18:24:26 -0500
On Jun 6, 2008, at 5:48 PM, Bill Bumgarner wrote:
On Jun 6, 2008, at 3:23 PM, Quincey Morris wrote:
In a GC-only app, I frequently use a pattern along these lines:
NSData* data = <get it from somewhere>;
const unsigned char* bytes = [data bytes];
NSUInteger count = [data length];
for (NSUInteger i = 0; i < count; i++)
something = bytes [i];
In any case, you need to make sure that <data> stays alive
throughout the entire lifespan of the bytes pointer. This is no
different than in non-GC. If <data> were released sometime before
the for loop were done, a similar crash would occur.
I'm a bit confused by this. In non-GC, data would not be released
during the loop execution. Let's assume that it was autoreleased
during the 'get it from somewhere'. It would only be actually
released when execution returns to the main run loop; clearly after
the entire loop above would be executed.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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