Destroying Arrays

Like BSTRs, SAFEARRAYs must be freed before they can be destroyed. When Visual Basic passes an existing array to your DLL, it is passed as a static array that cannot be destroyed. Your DLL can create its own arrays, however. When you no longer need an array, it should be destroyed.

You must be careful when you destroy an existing array. Freeing the array frees only the array memory; if the array contains any pointers (such as BSTR values), these will not be freed. In this case, you must free each BSTR element individually and then free the array. If you do not know what the array contains, you should probably not free or redimension the array.