Move more cleanup to endProcessing because dealloc won't be called otherwise.