Table of Contents
Previous Section
By moving a component's variable initialization routines from its init method to its awake method and implementing a sleep method to release those variables, you can reduce the space requirements for storing a component. For example, the code for DodgeLite's Main component could be changed to:
// rewritten DodgeLite Main.wos
id models, model, selectedModels;
id prices, price, selectedPrices;
id types, type, selectedTypes;
- awake {
anApplication = [WOApplication application];
models = [[anApplication modelsDict] allValues];
types = [[anApplication typesDict] allValues];
prices = [anApplication prices];
}
- sleep {
models = nil;
types = nil;
prices = nil;
}
Note that in WebScript you set a variable to nil to mark it for release. In Objective-C you send the object a release message:
- sleep {
[models release];
[types release];
[prices release];
}
Of course, what you save in storage by moving variable initialization to the awake method is lost in performance, since these variables will be reinitialized on each cycle of the request-response loop.
Table of Contents
Next Section