fixed a memory leak by using gc.collect()