close will just close the object to read the file, but X will still hold all your images in memory.
To solve this, you can use a similar approach to what is done for imagenet here 35 where images are loaded on the disk only when needed then deleted.