17

I can't find any documentation on how numpy handles unmapping of previously memory mapped regions: munmap for numpy.memmap() and numpy.load(mmap_mode).

My guess is it's done only at garbage collection time, is that correct?

Radim
  • 4,208
  • 3
  • 27
  • 38
  • 2
    It would be an excellent tool if NumPy supported some manually-controlled notion of `munmap`. For example, I could load some array `x` with some `mmap` mode turned on. At some point I read `x[0:100]`, and then later I read `x[101:200]`. I want to be able to call `numpy.munmap(x[0:100])`, and have the result be such that only the elements of `x[101:200]` are loaded in memory, and any references to `x[0:100]` would have to re-`mmap` them when evaluated. – ely Feb 20 '18 at 18:38

1 Answers1

16

Yes, it's only closed when the object is garbage-collected; memmap.close method does nothing.

You can call x._mmap.close(), but keep in mind that any further access to the x object will crash python.

Matti Lyra
  • 12,828
  • 8
  • 49
  • 67
Igor Nazarenko
  • 2,184
  • 13
  • 10