Does `String(unsafe_wrap(cstring, len, own=true))` free the memory it points to?

If I have a Cstring from a @ccall that I am responsible for freeing, does converting that Cstring to a Julia String via s = String(unsafe_wrap(Vector{UInt8}, Ptr{UInt8}(cstring), len, own=true)) automatically free the associated memory once s goes out of scope?

unsafe_string() (copy) is almost always what you want. The unsafe_wrap(own=true) pattern is only safe when you’re certain the pointer came from malloc and ownership transfers to you, but yes if know malloc was used and not a custom allocator.

The String constructor might make a copy anyway. If you want a copy-free wrap see GitHub - JuliaStrings/StringViews.jl: String-like views of arbitrary Julia byte arrays · GitHub this can be used with a custom array type with a finalizer to call the C functions to clean up the memory.