Ensure all resources are closed all the time.