Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Garbage collector vs variable lifetime



On Jun 6, 2008, at 7:05 PM, Ricky Sharp wrote:


On Jun 6, 2008, at 6:42 PM, Bill Bumgarner wrote:


Sorry -- let me clarify. If the <data> was either released in a different thread or if <data> were explicitly released in the above code, then you would see the same crash. I didn't mean to imply that <data> would be released under non-GC without some explicit action being taken.


Under GC, the situation isn't quite so clear.


That makes perfect sense. Sorry that I glossed over the 'other thread' bit.


What about using the data pointer directly in the loop? Would this prevent the GC thread from freeing that memory early? This sends a message to the data object at each iteration, so not as optimal as pointer arithmetic I suppose...


	NSData* data = <get it from somewhere>;
	NSUInteger count = [data length];
	for (NSUInteger i = 0; i < count; i++)
		[data getBytes:&something range:NSMakeRange(i, 1)];

Cheers,
George
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Garbage collector vs variable lifetime (From: Quincey Morris <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Bill Bumgarner <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Ricky Sharp <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Bill Bumgarner <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Ricky Sharp <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.