Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.tif files not released after reading #159

Closed
hustf opened this issue May 25, 2024 · 2 comments · Fixed by #160
Closed

.tif files not released after reading #159

hustf opened this issue May 25, 2024 · 2 comments · Fixed by #160

Comments

@hustf
Copy link

hustf commented May 25, 2024

What happens

read with default keyword arguments (sometimes?) leave .tif files "open". That is, I can't remove test files without closing Julia first.

When

In Windows OS, this happens with files made from scratch in GeoArrays.jl, and files downloaded from different sources. I don't believe the file content is the cause. The files can't be deleted from Powershell or Explorer, because they are 'open in Julia programming language'. Have not tested on other OS.

julia> fn = "Consolidated.tif";

julia> GeoArrays.read(fn)
155x155x1 Array{Float32, 3} with AffineMap([1.0 0.0; 0.0 -1.0], [18294.0, 6.937717e6]) and undefined CRS

julia> rm(fn)
ERROR: IOError: unlink("Consolidated.tif"): resource busy or locked (EBUSY)
...

Reading other files does not release the first file. After closing Julia, the files can be deleted.

Why

Not pinned down, perhaps some non-conforming ccalls? I could not find issues with the libraries online.

Workarounds

a) Drop cleaning up. This makes testing fail in some contexts.
b) Instead of read:

"""
    readclose(fnam)

A barrier for a possible issue with GeoArrays libraries. Keyword arguments not included.
"""
function readclose(fnam)
    file_task = Threads.@spawn GeoArrays.read(fnam)
    contents = fetch(file_task)
    GC.gc()            # Clean up resources explicitly after the operation
    contents::GeoArray # Type guarantee for the compiler, just like `read` 
end
@evetion
Copy link
Owner

evetion commented May 25, 2024

Thanks for making an issue, and great to see suggestions on a possible fix.

I've indeed seen such errors on Windows CI, but I thought it stemmed from lazy reading, but that should not happen with default kwargs. Let me investigate.

@hustf
Copy link
Author

hustf commented May 25, 2024

Thanks for the quick response.
I'm new to rasters and to this package, so it took a while for me to figure out that the returned GeoArray is sometimes lazy. Does the compiler know that, and compile methods for both cases? And perhaps, does it not release the reference because some method unnecessarily assumes that a geoarray is lazy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants