• 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
Re: Garbage collector vs variable lifetime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Garbage collector vs variable lifetime
      • From: Bill Bumgarner <email@hidden>
    • Re: Garbage collector vs variable lifetime
      • From: Nick Zitzmann <email@hidden>
References: 
 >Garbage collector vs variable lifetime (From: Quincey Morris <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: Garbage collector vs variable lifetime
  • Next by Date: Re: Garbage collector vs variable lifetime
  • Previous by thread: Re: Garbage collector vs variable lifetime
  • Next by thread: Re: Garbage collector vs variable lifetime
  • Index(es):
    • Date
    • Thread