cudaFree vector as function return

hi,

how to cudaFree vector as function return?

double* func (…)
{

return Vec;
}

in my application, the func is repeated and the size of Vec is big, which leads to memory problem. how i can free Vec in main()?

thanks.