Destroying Safe Arrays
You should always explicitly destroy Safe Arrays created by your application before the application exits. Otherwise, the Operating System will not release the memory used by the Safe Array and its data.
To destroy a Safe Array you can use f90VB’s procedure SafeArrayDestroy. SafeArrayDestroy performs several complex operations [12]:
Safe Arrays of variants will have VariantClear called on each member and Safe Arrays of BStrings will have StrFree called on each element. RecordClear will be called to release object references and other values of a record without deallocating the record.
If objects are stored in the array, the Release method is called on each object in the array.
The memory allocated for the data-block of the Safe Array is released.
The memory allocated for the Safe Array descriptor is released.
The Safe Array handle passed to SafeArrayDestroy is set to null.
These operations can also be performed using a two-step approach calling SafeArrayDestroyData and SafeArrayDestroyDescriptor.
A Fortran subroutine that receives a non-null Safe Array handle as an argument, should not destroy the passed Safe Array unless the subroutine returns a handle to a newly created Safe Array.