initialize and shutdown functions
initialize
The initialize
function is called by a text intelligence engine at startup. In Studio, this happens after every build operation. This is the default definition:
function initialize(cmdline) {
return true;
}
The cmdline
argument is reserved for future use.
This function is the right place to put the initialization of objects that are needed in other event handling functions.
The engine, in fact, will continue its execution, only if the initialize
function returns true
. If your code catches initialization errors and returns false
, the engine will stop, thus avoiding unwanted effects you'd surely have if you let the engine go on and have it execute other functions with global objects that have not corretcly been initialized.
shutdown
The shutdown
function is called by a text intelligence engine immediately before it stops. In Studio, this happens after every build operation but the first: the engine that was previously built is stopped and a new one is started.
This is the default definition:
function shutdown() {
}
This can be the place in which to deallocate global objects, especially in Studio, otherwise occupied memory is released only when you close Studio.
For example, the best practice is to put here REX.close()
, which closes every previously instantiated regular expression.