It is possible to destroy objects with the command destroy. For example,
- interpcom -> destroy xxx
will destroy the object xxx (if it exists). If the variable type is known (i.e. the type of variables in this object is between 0 and 6), the corresponding array is freed. When an object is destroyed, the function
void dest_prop(int, int, flow_data *);
will be called. This is useful in particular if the type of variables is 7 (undetermined type, see 6.5). This function should contain the procedure provided by the user to free the corresponding data. This function is not in the library. It must be present in the program that uses the command interpreter. It can be simply
void dest_prop(int typ, int i0, flow_data *flow_interp) { }
The argument flow_interp is the address of the flow_data structure corresponding to the current thread (cf. 10.4). The argument typ is the object type (the first to be defined in the initialization file is 0, the second 1, and so on), i0 is the object number. So the object to free is actually Obj[typ][i0]. In the example of 6.5, we could put the following function
void dest_prop(int typ, int i0, flow_data *flow_interp) { char **e; Data0 *D; if (typ == 2) { e = (char **) Obj[typ][i0].adresse; D = (Data0 *) e[0]; free_Data0(D); /* function supplied by the user to free data of type Data0 */ } }
In more complicated situations a specific command can also be written to destroy some kind of object. In the preceeding example the argument flow_interp is not used, but it may be used in more complicated situations. For instance if the destruction of an object would imply the destruction of another object, the function dest_prop should emulate the command destroy to destroy the associated object, by calling the corresponding function detruit_obj(int argc, char *argv[]) and we need to pass to it the parameter flow_interp (in argv[-1]).
The objects of an array of objects must be destroyed individually.
The function
void init_obj(int, flow_data *);
may be used to destroy all the objects of a given type : it deletes all the objects of the type given in the first argument. The second argument is a pointer to the flow_data structure corresponding to the running thread (cf. 10.4).