To avoid memory leak, don't forget to deallocate the dynamic memory before returning from the procedure.
For example, replace:
Code: Select all
.....
return * ps1
end function
Code: Select all
.....
function = * ps1
deallocate ps1
end function