simplify memory deallocation in sample