Flush listener registrations before garbage collecting queries/listeners