• 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: Transitioning to GC-supported
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Transitioning to GC-supported


  • Subject: Re: Transitioning to GC-supported
  • From: Jens Alfke <email@hidden>
  • Date: Mon, 26 Oct 2009 08:38:55 -0700


On Oct 26, 2009, at 6:45 AM, Dave Keck wrote:

1. Apply workaround for interior pointers by '[containingObject self];' at
the end of the method, to keep the containing object alive.

A valid point, but in my experience this is a rare problem: I have never run into an instance of a bug caused by interior pointers.


2. Go through every -dealloc and implement an -invalidate or equivalent for
cases where non-memory-related cleanup is needed, or -finalize if absolutely
necessary.

Yup, but you'll find the vast majority of your -dealloc methods only release memory so you don't need to create a -finalize.


3. Wrap all CF*Create(), CG*Create(), CF*Copy(), CG*Copy(), etc. with
CFMakeCollectable(), and replace corresponding CFRelease()s with a custom
macro - CFReleaseIfRC(). (This way, if I ever choose to go GC-only, I can
simply remove all calls to CFReleaseIfRC().)

You only need to worry about this if you cast a CFxxxRef to an NSxxx* and later call -release or -autorelease on it. If you just call CFRelease without keeping a longer-term reference to the object, you don't need to change anything.


Actually it's easier to call NSMakeCollectable, simply because its return type is id. Saves you a type-cast.

4. Search for every call to -retain, -alloc, -init pairs, and -copy. Verify
that the object being retained is strongly referenced, and if not, it must
be CFRetain()ed or -disableCollectorForPointer: must be called for it.

I'm not sure what you mean by this.

5. Search for every call to -release and -autorelease. If the object being
released is a CFType, then it must be CFReleaseIfRC() instead.

This is basically what I described above under #3.

6. Search for every use of '&', and use objc_assign_global() and
objc_assign_ivar() as necessary.

I don't know what you mean by this.

In summary, I think what you're saying is formally correct, but you're overestimating the amount of trouble. I have converted significant amounts of code to be GC-compatible, and only ran into minor problems. The biggest thing to watch out for is mixing CF and NS types, and mostly you just need to insert an NSMakeCollectable call to take care of those. It's really not that bad.

—Jens_______________________________________________

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: Transitioning to GC-supported
      • From: "Sean McBride" <email@hidden>
    • Re: Transitioning to GC-supported
      • From: Dave Keck <email@hidden>
References: 
 >Transitioning to GC-supported (From: Dave Keck <email@hidden>)

  • Prev by Date: Re: Professional Error Handling
  • Next by Date: Preparing for MOM versioning in version 1
  • Previous by thread: Transitioning to GC-supported
  • Next by thread: Re: Transitioning to GC-supported
  • Index(es):
    • Date
    • Thread