Skip to content

Commit f3fb539

Browse files
committed
Deprecate gc and gc_enable in favor of GC.gc and GC.enable
We document that these functions should not generally be used, and yet they're exported from Base. This moves the two functions into their own submodule, Base.GC, and deprecates the exported functions.
1 parent 3d84bbb commit f3fb539

File tree

20 files changed

+61
-30
lines changed

20 files changed

+61
-30
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ Deprecated or removed
954954

955955
* `ObjectIdDict` has been deprecated in favor of `IdDict{Any,Any}` ([#25210]).
956956

957+
* `gc` and `gc_enable` have been deprecated in favor of `GC.gc` and `GC.enable` ([#25616]).
958+
957959
Command-line option changes
958960
---------------------------
959961

@@ -1205,3 +1207,4 @@ Command-line option changes
12051207
[#25424]: https://github.com/JuliaLang/julia/issues/25424
12061208
[#25532]: https://github.com/JuliaLang/julia/issues/25532
12071209
[#25545]: https://github.com/JuliaLang/julia/issues/25545
1210+
[#25616]: https://github.com/JuliaLang/julia/issues/25616

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,9 @@ end
27942794
@deprecate findn(x::AbstractMatrix) (I = findall(!iszero, x); (getindex.(I, 1), getindex.(I, 2)))
27952795
@deprecate findn(x::AbstractArray{T, N}) where {T, N} (I = findall(!iszero, x); ntuple(i -> getindex.(I, i), N))
27962796

2797+
@deprecate gc GC.gc
2798+
@deprecate gc_enable GC.enable
2799+
27972800
# issue #9053
27982801
if Sys.iswindows()
27992802
function Filesystem.tempname(uunique::UInt32)

base/exports.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,9 @@ export
902902
include_dependency,
903903

904904
# RTS internals
905+
GC,
905906
finalizer,
906907
finalize,
907-
gc,
908-
gc_enable,
909908
precompile,
910909

911910
# misc

base/gcutils.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,30 @@ Immediately run finalizers registered for object `x`.
3838
finalize(@nospecialize(o)) = ccall(:jl_finalize_th, Cvoid, (Ptr{Cvoid}, Any,),
3939
Core.getptls(), o)
4040

41+
module GC
42+
43+
export gc
44+
4145
"""
42-
gc()
46+
GC.gc()
47+
48+
Perform garbage collection.
4349
44-
Perform garbage collection. This should not generally be used.
50+
!!! warning
51+
Excessive use will likely lead to poor performance.
4552
"""
4653
gc(full::Bool=true) = ccall(:jl_gc_collect, Cvoid, (Int32,), full)
4754

4855
"""
49-
gc_enable(on::Bool)
56+
GC.enable(on::Bool)
5057
5158
Control whether garbage collection is enabled using a boolean argument (`true` for enabled,
52-
`false` for disabled). Return previous GC state. Disabling garbage collection should be
53-
used only with extreme caution, as it can cause memory use to grow without bound.
59+
`false` for disabled). Return previous GC state.
60+
61+
!!! warning
62+
Disabling garbage collection should be used only with caution, as it can cause memory
63+
use to grow without bound.
5464
"""
55-
gc_enable(on::Bool) = ccall(:jl_gc_enable, Int32, (Int32,), on) != 0
65+
enable(on::Bool) = ccall(:jl_gc_enable, Int32, (Int32,), on) != 0
66+
67+
end # module GC

doc/src/base/base.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ Base.@functionloc
331331
## Internals
332332

333333
```@docs
334-
Base.gc
335-
Base.gc_enable
334+
Base.GC.gc
335+
Base.GC.enable
336336
Meta.lower
337337
Meta.@lower
338338
Meta.parse(::AbstractString, ::Int)

stdlib/FileWatching/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Test, FileWatching
3+
using Test, FileWatching, Base.GC
44

55
# This script does the following
66
# Sets up n unix pipes

stdlib/Mmap/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Test, Mmap, Random
3+
using Test, Mmap, Random, Base.GC
44

55
file = tempname()
66
write(file, "Hello World\n")

stdlib/SharedArrays/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl"))
66
addprocs_with_testenv(4)
77
@test nprocs() == 5
88

9-
@everywhere using Test, SharedArrays
9+
@everywhere using Test, SharedArrays, Base.GC
1010

1111
id_me = myid()
1212
id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]

stdlib/SparseArrays/test/sparse.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Base.LinAlg: mul!, ldiv!, rdiv!
44
using Base.Printf: @printf
5+
using Base.GC
56
using Random
67

78
@testset "issparse" begin

stdlib/SuiteSparse/test/cholmod.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SuiteSparse.CHOLMOD
44
using DelimitedFiles
55
using Test
6+
using Base.GC
67

78
# CHOLMOD tests
89
srand(123)

0 commit comments

Comments
 (0)