fix possible race condition in collect_gargage