close before destroying. fixes #1550