during shutdown, only free the heap if we waited for foreign calls to exit