Fix bug in garbageCollect