The executive is responsible for managing Objects successfully returned as output by modules and for the memory allocated to those Objects. Any memory allocated or any Objects created that are not returned as output are the responsibility of the module. For instance, in an unsuccessful execution of a module, no Objects are returned. It is important that the programmer remember this difference when writing a module.
Memory allocation results from either of the following:
In general, allocations resulting from these calls must be freed before returning.
On successful return, memory allocated for the use of these routines does not usually need to be freed: the Objects returned are managed by the executive, and the module is not responsible for their deletion. However, in case of error, no output Objects are returned, and the module is responsible for deleting all Objects created.
When a Field is placed in a Group, the Field is deleted when the Group is deleted; and, on error, only the Group should be deleted. Similarly, an Array placed in a Field is deleted when the Field is deleted. For that reason it is often helpful to set the pointer of a Field or Array to NULL after placing it in a higher-level Object. The Field or Array can then be safely deleted on error, regardless of whether it has been placed in a higher-level Object.
In Data Explorer, reference counts typically require no special action from the user. Thus modules seldom need to call DXReference for any reason, and they usually call DXDelete only to clean up Objects after an error. Note the following:
This means you can create Array Objects and use DXSetComponentValue to add them to a Field as a component, without having to call DXDelete: the Array will be deleted when the Field itself is deleted. (However, if an error occurs before you add the Array to the Field, you must call DXDelete.)