On Wed, Sep 24, 2008 at 5:05 AM, j o a r <[EMAIL PROTECTED]> wrote:
>
> On Sep 23, 2008, at 10:39 AM, Greg Parker wrote:
>
>> You should first clean up anything you already did in your -init, then
>> call [super dealloc]. [self dealloc] or [self release] are bad because they
>> might call some subclass's -dealloc method even though the subclass's -init
>> hasn't done anything yet.
>
>
> If calling [super dealloc] is indeed the recommended way of doing this, we
> should file an enhancement request on the documentation. The only time it
> currently talks about anything related to this topic, it is to say that:
>
> "You should never invoke dealloc directly (other than when you invoke
> super's implementation in a custom dealloc method)."
>
> Why not [super release]?

The documentation also says that "When an init… method cannot
initialize an object, it should: Release the newly allocated object
(in memory-managed code)…"

I can imagine scenarios, albeit unlikely ones, where calling [super
dealloc] rather [self release] might confuse things.

I would strongly recommend designing all classes so that dealloc
safely runs even if init hasn't although I wouldn't rely on it in
anyone else's code.

I'd also try and avoid init methods that fail or return a different
pointer if you think it's likely the class is going to be subclassed.

-- Chris
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to