handle terminated gc context

closes #507
Merge pull request #509 from minrk/gc-teardown

handle terminated gc context