• 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: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful


  • Subject: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • From: Chris Suter <email@hidden>
  • Date: Thu, 7 Feb 2008 12:48:22 +1100


On 07/02/2008, at 12:06 PM, John Engelhart wrote:

However, consider for a moment if it was a type attribute, and followed type attribute rules, and how this would effect the examples cited. Off the top of my head, I think treating it as a type attribute would have prevent every single error I've pointed out. Hypothetically, consider if UTF8String propagated the __strong type, and the assignment of its pointer to the ivar 'const char *'.

The compiler would fail to compile the code, and generate an error.

I don't think it should be a type qualifier. It would mean that you wouldn't be able to do things like:


puts ([myString UTF8String])

without getting a compiler warning.

Oddly, I had to add a second NSLog() in order to get some kind of lossage, but I think it's fair to chalk this up to the semi-random nature of allocations.

I think that would have been because the pointer returned by UTF8String was still on the stack or in a register.


The above example is now perfectly legal by everyones definition of how things were under retain/release, and I correctly clear the pointer before it goes out of scope, and demonstrates that the GC system can, and does, reclaim live data out from under you.

I think your example is contrived. Whilst it's legal in the retain/ release world you wouldn't ever write anything like that.


The solution to all of this is, as has already been stated, is to understand the contract that UTF8String promises and to make your own arrangements if you want to hang on to the value.

- Chris

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
      • From: John Engelhart <email@hidden>
References: 
 >Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: John Engelhart <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: Alastair Houghton <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: John Engelhart <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: Chris Hanson <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: John Engelhart <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: "Hamish Allan" <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: Alastair Houghton <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: John Engelhart <email@hidden>)

  • Prev by Date: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • Next by Date: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • Previous by thread: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • Next by thread: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • Index(es):
    • Date
    • Thread