Documentation Archive Developer
Search
Table of Contents Previous Section

Initialization and Deallocation Methods

Like all objects, WOApplication, WOSession, and WOComponent implement initialization methods (or constructors in Java). Because most subclasses require some unique initialization code, these are the methods that you override most frequently. In WebScript, the initialization methods are init and awake. In Java, the initialization methods are the constructor for the class and awake.

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