Skip to content

Commit

Permalink
Simplify the GC.gc interface. (#34303)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored and JeffBezanson committed Jan 8, 2020
1 parent 41501a5 commit b0ed147
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
25 changes: 8 additions & 17 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,20 @@ Module with garbage collection utilities.
"""
module GC

# @enum-like structure
struct CollectionType
x::Int
end
Base.cconvert(::Type{Cint}, collection::CollectionType) = Cint(collection.x)

const Auto = CollectionType(0)
const Full = CollectionType(1)
const Incremental = CollectionType(2)

"""
GC.gc(full::Bool=true)
GC.gc(collection::CollectionType)
GC.gc()
GC.gc(full::Bool)
Perform garbage collection. The argument `full` determines whether a full, but more costly
collection is performed. Otherwise, heuristics are used to determine which type of
collection is needed. For exact control, pass an argument of type `CollectionType`.
Perform garbage collection. The argument `full` determines the kind of collection: A full
collection scans all objects, while an incremental collection only scans so-called young
objects and is much quicker. If called without an argument, heuristics are used to determine
which type of collection is needed.
!!! warning
Excessive use will likely lead to poor performance.
"""
gc(full::Bool=true) = ccall(:jl_gc_collect, Cvoid, (Cint,), full)
gc(collection::CollectionType) = ccall(:jl_gc_collect, Cvoid, (Cint,), collection)
gc() = ccall(:jl_gc_collect, Cvoid, (Cint,), 0)
gc(full::Bool) = ccall(:jl_gc_collect, Cvoid, (Cint,), full ? 1 : 2)

"""
GC.enable(on::Bool)
Expand Down
1 change: 0 additions & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,6 @@ end
@testset "GC utilities" begin
GC.gc()
GC.gc(true); GC.gc(false)
GC.gc(GC.Auto); GC.gc(GC.Full); GC.gc(GC.Incremental)

GC.safepoint()
end

0 comments on commit b0ed147

Please sign in to comment.