[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 1.5.0.9 (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.)
[1]http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html
--
Jens Ayton
- Alloc/dealloc etiquette, Michael Hopkins, 2007/02/17
- Re: Alloc/dealloc etiquette, Michael Ash, 2007/02/17
- Re: Alloc/dealloc etiquette, Sherm Pendley, 2007/02/17
- Re: Alloc/dealloc etiquette, David Phillip Oster, 2007/02/17
- Re: Alloc/dealloc etiquette, David Phillip Oster, 2007/02/17
- Re: Alloc/dealloc etiquette, Sherm Pendley, 2007/02/17
- Re: Alloc/dealloc etiquette, Michael Ash, 2007/02/18
- Re: Alloc/dealloc etiquette, David Phillip Oster, 2007/02/19
- Re: Alloc/dealloc etiquette, Michael Ash, 2007/02/19
Re: Alloc/dealloc etiquette, Michael Hopkins, 2007/02/17
Re: Alloc/dealloc etiquette,
Jens Ayton <=