reduce a memory leak of closing dir