Framework: clean up resources after task calls Exit()

LGTM