Skip to content

Commit ce211b9

Browse files
twavvJeffBezanson
authored andcommitted
Improve docstring for finalizer. (#34285)
1 parent d64c971 commit ce211b9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

base/gcutils.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ Register a function `f(x)` to be called when there are no program-accessible ref
1212
this function is unpredictable.
1313
1414
`f` must not cause a task switch, which excludes most I/O operations such as `println`.
15-
`@schedule println("message")` or `ccall(:jl_, Cvoid, (Any,), "message")` may be helpful for
16-
debugging purposes.
15+
Using the `@async` macro (to defer context switching to outside of the finalizer) or
16+
`ccall` to directly invoke IO functions in C may be helpful for debugging purposes.
17+
18+
# Examples
19+
```julia
20+
finalizer(my_mutable_struct) do x
21+
@async println("Finalizing \$x.")
22+
end
23+
24+
finalizer(my_mutable_struct) do x
25+
ccall(:jl_safe_printf, Cvoid, (Cstring, Cstring), "Finalizing %s.", repr(x))
26+
end
27+
```
1728
"""
1829
function finalizer(@nospecialize(f), @nospecialize(o))
1930
if isimmutable(o)

0 commit comments

Comments
 (0)