Improve free-on-destroy functionality of stack.