[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alloc/dealloc etiquette

From: Jens Ayton
Subject: Re: Alloc/dealloc etiquette
Date: Sun, 18 Feb 2007 19:36:27 GMT
User-agent: Thunderbird (Macintosh/20061207)

Michael Ash:
> You should never override +alloc. +alloc is just a convenience method for 
> +allocWithZone: with a NULL argument, so if you need to override one, you 
> should override +allocWithZone:. However, there is basically never a 
> reason to do this. Allocating objects is generally something where the 
> base class does it right and you should have no need to modify its 
> behavior when doing so.

The chapter “Creating a Singleton Instance” of Apple’s “Cocoa
Fundamentals Guide”[1] presents a template implementation of a singleton
which ensures uniqueness in +allocWithZone:. While it’s possible to
ensure singleton status in -init, and the singleton pattern itself can
be and has been criticised, using the template from Apple’s
documentation is a reasonably reasonable case where overriding
+allocWithZone: is motivated. :-) (It does, however, call [super
allocWithZone: in the case where allocation actually happens.)


Jens Ayton

reply via email to

[Prev in Thread] Current Thread [Next in Thread]