Mmap.mmap leaves the file open

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?

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().

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

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.

1 Like

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

Sorry, really GC.gc () helped