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

**URL:** <https://discourse.julialang.org/t/why-trying-to-remove-arrow-file-fails-with-ioerror-on-windows/105273>\
**Category:** General Usage\
**Tags:** io, arrow\
**Created:** [October 22, 2023, 12:54am UTC](https://discourse.julialang.org/t/why-trying-to-remove-arrow-file-fails-with-ioerror-on-windows/105273 "2023-10-22T00:54:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [October 22, 2023, 12:54am UTC](https://discourse.julialang.org/t/why-trying-to-remove-arrow-file-fails-with-ioerror-on-windows/105273/1 "2023-10-22T00:54:06Z")

</div>

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

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

```

this throws:

```julia
ERROR: IOError: unlink("MWE.arrow"): permission denied (EACCES)
Stacktrace:
 [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
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
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver3)
  Threads: 1 on 12 virtual cores

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [October 23, 2023, 2:56am UTC](https://discourse.julialang.org/t/why-trying-to-remove-arrow-file-fails-with-ioerror-on-windows/105273/2 "2023-10-23T02:56:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [October 23, 2023, 4:56pm UTC](https://discourse.julialang.org/t/why-trying-to-remove-arrow-file-fails-with-ioerror-on-windows/105273/3 "2023-10-23T16:56:31Z")

</div>

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
