Table of Contents Previous Section

The sleep and dealloc Methods

Complementing awake and init, respectively, 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 an object's involvement in a transaction. The dealloc method is invoked just before an object is destroyed.

In Objective-C you deallocate instance variables by sending them release. In WebScript, on the other hand, all you need to do (in sleep) is set the instance variables to nil. WebScript has a "garbage-collection" mechanism that automatically disposes of unreferenced objects. For this reason, there's seldom a reason for implementing dealloc in a script.

Table of Contents Next Section