• 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 Duniho <email@hidden>
  • Date: Thu, 25 Jun 2009 13:16:07 -0700

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

[...] .NET users often call Dispose()
explicitly, because it is useful in situations other than inside using
blocks.

Though, to be clear (lest the tendency to want to put down the other be allowed to go too far)...


The requirement in .NET that Dispose() be safe to call multiple times has very little to do with how _client_ code is expected to use it, and more to do with the GC system. In particular, the order of finalizer execution is indeterminate, and the usual job of a finalizer is to call Dispose() on the object in which it's implemented, which in turn may call Dispose() on other objects referenced by that object.

Without a requirement that Dispose() be safe to call multiple times, the caller of Dispose() would have to always check to see whether the object has been disposed yet, because an object that is being disposed by some other object being finalized might already have been disposed by the first object's finalizer.

Certainly it would be unusual, and generally a sign of sloppy programming, for _client_ code to call Dispose() on an object more than once (or for the finalizer to be executed, for that matter). The rules are there to make the system more robust, not to encourage sloppy programming (though of course, unfortunately, the former does sometimes lead to the latter).

I admit, I'm not well-versed on what the equivalent paradigm in Obj-C/ Cocoa is. But, surely it's useful even in Obj-C/Cocoa to provide protections within the language and framework against sloppy programming, even as it should be clear that sloppy programming isn't to be tolerated.

Pete
_______________________________________________

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: Peter Ammon <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: GC pros and cons
  • Next by Date: Re: Search in ABPeoplePickerView not working
  • Previous by thread: Re: GC pros and cons
  • Next by thread: Re: GC pros and cons
  • Index(es):
    • Date
    • Thread