'When mmap is in use these objects hold a reference to the mmap of the
file (so there is only one, shared by all HDUs that reference this
file).
This will close the mmap if there are no arrays referencing it.'

def _maybe_close_mmap(self, refcount_delta=0):

    if ((self._mmap is not None) and (sys.getrefcount(self._mmap) == (2 + refcount_delta))):
        self._mmap.close()
        self._mmap = None
