flose files & free memory when not needed