Someday destructors may be defined/automatically called, but today there will 
be no clean-up without the `close` call. You may not need to/want to clean-up 
anyway.

need to: `memfiles.open()` creates a memory mapping, but does not (by default) 
keep the file descriptor open. The only thing the `mf.close` above does is call 
`munmap`. Memory maps are a less scarce resource than file handles due more to 
default OS limits than anything else. Being much less scarce, it's not quite as 
bad to leak it.

want to: You might even want to leak it on purpose if you wanted to keep the 
string data alive beyond the lifetime of the procedure invocation. E.g., you 
may want to return an `MemSlice` or a `Table` with them as keys or values. They 
are just pointers to that memory mapped region (hence zero copy) which means if 
you `mf.close/munmap` the pointers become invalid.

Of course, if you are leaking millions of memory mappings then even small leaks 
can grow to be burdensome on the OS -- if you don't need continued access to 
the data. So, as with all resource management there is a balance of concerns 
and trade offs.

Reply via email to