Deletion of b and a getting deleted own its own

how will deletion of a var that is get value from another function can delete the dynamic memory allocated in the function when we delete the var in main