Thanks to everybody above! And I think I've got some idea to overwhelm that:
Maybe I can wrote the program into two: one for iterate through all files, the other do the "true" process on each file. After finished processing each file(maybe very large), the second process is completed, resource is released, and my computer won't get filled.