Re: GC pros and cons
Re: GC pros and cons
- Subject: Re: GC pros and cons
- From: Peter Ammon <email@hidden>
- Date: Thu, 25 Jun 2009 13:45:54 -0700
On Jun 25, 2009, at 1:16 PM, Peter Duniho wrote:
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).
Thanks for that explanation! That makes sense. I'm happy that the
idempotence of Dispose() has a sane justification.
_______________________________________________
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