The syntax diagram of Objective-C classes shows that the notion of constructor and destructor is not supported in Objective-C. New instances are created in a 2-step process:
The following code demonstrates this:
By convention, the initXXX method will return Nil if initialization of some fields failed, so it is imperative that the result of the function is tested.
Similarly, no privileged destructor exists; By convention, the dealloc method fullfills the cleanup of the instances. This method can be overridden to perform any cleanup necessary. Like Destroy, it should never be called directly, instead, the release method should be called instead: All instances in Objective-C are reference counted, and release will only call dealloc if the reference count reaches zero.