If some of the file system operations failed, System.gc() was called in a loop. Now it is called once at most.