• 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: Peter Ammon <email@hidden>
  • Date: Thu, 25 Jun 2009 13:14:45 -0700


On Jun 25, 2009, at 12:11 PM, Kyle Sluder wrote:

On Thu, Jun 25, 2009 at 11:39 AM, Peter Ammon<email@hidden> wrote:
Are you saying that it's not sloppy to close a file twice, unlock a lock
twice, etc.?

It sounds to me like you were originally referring to language implementation sloppiness, which has nothing to do with closing a file twice, unlocking locks multiple times, etc. (client sloppiness).

Well, I can make my point with an analogy.

Anyone who has written C or C++ has committed a double free() at some point. This usually indicates that parts of the program aren't coordinating properly. We can apply ad-hoc fixes, but this is a common-enough error that it's worth coming up with a general solution. Two possible solutions are:

1) Improve coordination techniques, such by adding garbage collection, reference counting, etc.
2) Require that malloc be robust against multiple free()s on the same pointer


The second solution is a lot easier to implement. But it's really just papering over the problem, because double free()s are found with other bugs, such as deference-after-free or race conditions.

So when I see that Dispose() is required to be robust against multiple calls on the same object, it makes me think they encountered the same problem as double free(), but chose the second solution. Client sloppiness thus informed the framework design.

In any case, it's been my experience that GC makes memory management much easier, but precious resource management somewhat harder. It's harder because GC forces more of a divorce between the management of memory and precious resources, and the precious resource management techniques are about on the level with C circa 1989.

I mean, C# has the using statement, which works well as long as your precious resource's lifetime is tied to some scope. And we have the explicit Dispose() call, which works well as long as you have some external way to coordinate between multiple clients of the object. There's an obvious analogy to stack allocation and free(), respectively.

-Peter

_______________________________________________

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: GC pros and cons
      • From: Michael Ash <email@hidden>
    • Re: GC pros and cons
      • From: Bill Bumgarner <email@hidden>
References: 
 >Re: GC pros and cons (From: Quincey Morris <email@hidden>)
 >Re: GC pros and cons (From: Chris Idou <email@hidden>)
 >RE: GC pros and cons (From: Jeff Laing <email@hidden>)
 >Re: GC pros and cons (From: "Stephen J. Butler" <email@hidden>)
 >Re: GC pros and cons (From: Peter Ammon <email@hidden>)
 >Re: GC pros and cons (From: Kyle Sluder <email@hidden>)
 >Re: GC pros and cons (From: Peter Ammon <email@hidden>)
 >Re: GC pros and cons (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Recalculating NSTableView row sizes during a live column resize
  • Next by Date: Re: GC pros and cons
  • Previous by thread: Re: GC pros and cons
  • Next by thread: Re: GC pros and cons
  • Index(es):
    • Date
    • Thread