Re: question about -init methods
Re: question about -init methods
- Subject: Re: question about -init methods
- From: Bill Bumgarner <email@hidden>
- Date: Sun, 9 Jul 2006 23:34:42 -0700
On Jul 9, 2006, at 10:47 PM, Vinay Prabhu wrote:
The *can* be done depends upon the requirement...
Instead of releasing and recreating already created object (improves
the
performance, at least in my application),
one can re-use already created object. This concept is used in the
"shared
object" approach.
"Shared objects" are typically implemented as a single instance of a
class that is used throughout the runtime of the application.
This shared instance is created exactly once and only one designated
initializer is used to do so.
It is not OK to call a designated initializer more than once on any
given instance of a class. Even in classes you design it isn't OK for
two reasons; first, it is completely against the design pattern of
Cocoa and, secondly, you cannot be guaranteed that calling through to -
init more than once in any given instance on NSObject -- something you
really should do in your designated initailizer (unless there is some
other initializer you should be using) -- is a safe operation.
If you know how to implement entire dealloc method, you need not
call super
dealloc :-)
This is incorrect. There is no possible way to "know" how to
deallocate the memory associated with 'self' without breaking
encapsulation of NSObject -- without releasing memory that it
allocated in the first place. Nor is there any way to know what
other buffoonery may occur in various -dealloc methods above your
class in the hierarchy.
It is simply not a safe or correct thing to do. Class inheritance
exists for a reason.
b.bum
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden