In-memory file should only be closed, if it is not already