Method to unsafely close a mmap

Currently the Mmap.mmap function uses a finalizer to handle calling munmap or UnmapViewOfFile when the array is garbage collected.

It is useful to be able to do this finalization eagerly despite the potential risks if there are any unexpected references. Ref:

Currently CSV.jl uses does the following as a workaround:

Could a function that does this be added to the Mmap API as @topolarity suggested in attach finalizer in `mmap` to the correct object by KristofferC · Pull Request #54210 · JuliaLang/julia · GitHub

1 Like

We already know that a well placed GC call can have the desired effect. The downside is that garbage collection is expensive and probably does (much) more than is necessary for mmap alone. So my naive view is that it should be possible to isolate that bit of the GC call that does the trick for mmap and implement that as part of the mmap API.

1 Like