Both init and awake perform initialization tasks, but they are invoked at different times during an object's life. The init message (or the constructor in Java) is sent once, when the object is first created. In contrast, awake is sent at the beginning of each cycle of the request-response loop that the object is involved in. Thus, it may be sent several times during an object's life.
Complementing awake and init are the sleep and dealloc methods. These methods let objects deallocate their instance variables and perform other clean-up tasks. The sleep method is invoked at the end of each cycle of the request-response loop, whereas the dealloc method is invoked at the end of the object's life.
The dealloc method is used primarily for Objective-C objects. Standard dealloc methods in Objective-C send each instance variable a release message to make sure that the instance variables are freed. WebScript and Java, because they have automatic garbage collection, usually make a deallocation method unnecessary. If you find it necessary, you can implement dealloc in WebScript and finalize in Java.
Table of Contents Next Section