• 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: GC pros and cons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GC pros and cons


  • Subject: Re: GC pros and cons
  • From: James Gregurich <email@hidden>
  • Date: Fri, 26 Jun 2009 14:01:09 -0700

sure. if I'm sharing ownership of an object with the OS or some library, then I'm granting that code the option to keep the object around a long as it needs it. You're right. I can't predict exactly when the object might go away. If something isn't going away, it is because some system is actually keeping it around for a reason. I can code around that reality to keep my code running in an orderly and predictable fashion.

That isn't the same thing as my system being dependent on when a background process kicks in and starts scanning memory looking for pointers in use.

Aside from that, for objects that are entirely owned by my code, I can precisely control their lifetimes by the retain count. There is zero non-determinism there.

shared_ptr does retain counting in a way that is easy to maintain and extend without the perils of manually releasing and retaining pointers.  That gives me the reliability and safety I need without introducing a whole new unknown-element to my code base that will cause its own issues that I'll have to code around.


another benefit....shared_ptr is cross platform.  so, on the mac, I store objc objects in them. On windows, the same datamembers can take windows-specific structures and manage them.   shared_ptr<void> works great to put in a header intended to be on multiple platforms. in the implementation file, I can stick whatever I want in that shared_ptr and give it a custom deleter. this makes it really straightforward to use common header files with OS-specific implementations.

yea...yea...yea...you Apple employees don't have to worry about Windows, but I'm not that fortunate.  :)




On Friday, June 26, 2009, at 12:08PM, "Bill Bumgarner" <email@hidden> wrote:
>On Jun 26, 2009, at 1:31 PM, James Gregurich wrote:
>> If my resource is handed off to some external subsystem for release
>> and I can't DETERMINE the order of the releases with respect to each
>> other and other components of my code, then I would call that non-
>> deterministic and undesirable.
>
>As soon as your resource is handed off to any subsystem that you did
>not write, you can't determine the order of releases.   Said subsystem
>might release or it might cache for a while or it might retain it for
>purposes of background processing (to be released later) or it might
>autorelease or it might retain then autorelease in a different thread.
>
>The point is the same as -retainCount.  Once your object goes through
>any of the system APIs, there is a chance that the retain count will
>change and said behavior may differ based on architecture, OS release,
>or something else.
>
>b.bum
>
>
>
_______________________________________________

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

  • Prev by Date: Re: Substituting characters in a UITextField
  • Next by Date: Re: Number of images in main bundle folder (iPhone)
  • Previous by thread: Re: GC pros and cons
  • Next by thread: Re: GC pros and cons
  • Index(es):
    • Date
    • Thread