Mmap.mmap leaves the file open


#1

Hello, here is my code

open(filename, "w+") do io
			C = Mmap.mmap(io, BitArray, (64,10^3));
			BinX = getHash(r.x)
			for p=1:length(BinX)
				C[p, 1] = parse(Int, BinX[p])
			end
			Mmap.sync!(C);		
end

After I try to open or delete the created file, but I receive a message that the file is occupied by another program. How to close a file?


#2

Most likely, C hasn’t been garbage collected. First make sure you’re not storing the return value somewhere (the fact that you need that semicolon means this block returns C to the caller). Then try calling GC.gc().


#3

I tried GC.gc (), but the result is the same, with the exception of performance degradation.


#4

A runnable example might help (your example references lots of variables that we don’t have). Also details about your platform: Windows is quite different from Linux, for example.


#5

I’m not entirely sure whether this works, but you could also try to call finalize(C) after the Mmap.sync!(C); call.


#6

Sorry, really GC.gc () helped