Skip to content

Commit

Permalink
Improve docstring for finalizer. (#34285)
Browse files Browse the repository at this point in the history
  • Loading branch information
twavv authored and KristofferC committed Apr 11, 2020
1 parent 332d730 commit e42c81b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ Register a function `f(x)` to be called when there are no program-accessible ref
this function is unpredictable.
`f` must not cause a task switch, which excludes most I/O operations such as `println`.
`@schedule println("message")` or `ccall(:jl_, Cvoid, (Any,), "message")` may be helpful for
debugging purposes.
Using the `@async` macro (to defer context switching to outside of the finalizer) or
`ccall` to directly invoke IO functions in C may be helpful for debugging purposes.
# Examples
```julia
finalizer(my_mutable_struct) do x
@async println("Finalizing \$x.")
end
finalizer(my_mutable_struct) do x
ccall(:jl_safe_printf, Cvoid, (Cstring, Cstring), "Finalizing %s.", repr(x))
end
```
"""
function finalizer(@nospecialize(f), @nospecialize(o))
if isimmutable(o)
Expand Down

0 comments on commit e42c81b

Please sign in to comment.