• 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: Ben Trumbull <email@hidden>
  • Date: Mon, 4 Feb 2008 17:56:36 -0800

Then take a look again at the method prototype:

- (const char *)UTF8String; // Convenience to return null-terminated UTF8 representation

Can you clearly and concisely articulate why the pointer returned from
this particular method requires a __strong qualifier?

Yes. You're trying to store the pointer somewhere besides a root.

The documentation articulates the initial root set (strong globals, stack references, objects with CFRetains). ivars with a type declaration of id (or some derivative) are always treated as __strong unless you use __weak to get a zero'ing weak reference instead. If you want an object type to be a non-zeroing weak reference (usually wrong, but on rare occasion useful) you need to declare it void*

- (const char *)hexString
{
   char *hexPtr = NULL;
   asprintf(&hexPtr, "0x%8.8x", myIvar);
   return(hexPtr);
}

Now what?

asprintf() is documented to place a result in hexPtr that requires you call free() upon it. Your code needs to do that regardless of whether you adopt retain/release or GC. The documentation discusses how GC replaces the retain/release/dealloc/autorelease reference counting. You should not infer that it also replaces free() or other memory models found on the system like Carbon or C++.


Mixing malloc memory with GC memory under the Leopard GC system is quite difficult. However, using CoreFoundation objects instead of raw malloc can greatly simplify this.

We can be reasonably sure that the pointer to the UTF8String is 'visible' before we call the collector

This statement is wrong. The class definition for GCTest states that 'title' should not be followed during scanning to determine live-ness.
--


-Ben
_______________________________________________

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: Wade Tregaskis <email@hidden>
  • Prev by Date: Re: PDFAnnotationLine problem
  • Next by Date: NIB file "includes"?
  • Previous by thread: Re: Login item support for Panther, Tiger and Leopard
  • Next by thread: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • Index(es):
    • Date
    • Thread