Re: Alloc/dealloc etiquette
Jens Ayton <[email protected]> Sun, 18 Feb 2007 19:36:27 GMT
| Newsgroups | gmane.comp.lib.gnustep.user |
|---|---|
| Organization | Tending towards entropy |
| Message-ID | <%[email protected]> |
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