Why trying to remove .arrow file fails with IOError on Windows?

This is (hopefully) an MWE of my actual problem:

using Arrow, DataFrames
if true
    data = DataFrame(a=1:4, b=["M", "F", "F", "M"])
    Arrow.write("MWE.arrow", data; file = false)

this throws:

ERROR: IOError: unlink("MWE.arrow"): permission denied (EACCES)
 [1] uv_error
   @ .\libuv.jl:100 [inlined]
 [2] unlink(p::String)
   @ Base.Filesystem .\file.jl:972
 [3] rm(path::String; force::Bool, recursive::Bool)
   @ Base.Filesystem .\file.jl:283
 [4] rm(path::String)
   @ Base.Filesystem .\file.jl:273
 [5] top-level scope
   @ REPL[2]:7

I don’t actually get if this is a bug somewhere in Arrow.jl or am I doing something wrong. Notice that if I remove the if statement wrapping the code, the problem strangely disappears. Notice also that the problem is Windows specific since other OS don’t complain about it:

julia> versioninfo()
Julia Version 1.9.3
Commit bed2cd540a (2023-08-24 14:43 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 12 × AMD Ryzen 5 5600H with Radeon Graphics
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver3)
  Threads: 1 on 12 virtual cores

I think there may be a similar problem with memory mapping a file on Windows.

yes, indeed, in the end I understood that the problem is the concurrent occurence of this memory mapping problem and that the deletion of the reference of the Arrow stream doesn’t happen immediately after the call to the GC, so that the file is still locked. Putting the code above the GC call in a function solves the problem