wait for exit and release resource