Dum*_*fus 7 garbage-collection julia
我还有一个关于Julia垃圾收集的问题.这是一个最小的例子:
function OscarTheGrouch()
A = rand(Float32, 20000, 20000);
A = 0;
gc();
end
Run Code Online (Sandbox Code Playgroud)
调用OscarTheGrouch()会导致RAM使用量增加1.6GB.gc()之后调用会导致它下降1.6GB.
相反,只需在全局范围内执行函数内部的代码,即执行
A = rand(Float32, 20000, 20000);
A = 0;
gc();
Run Code Online (Sandbox Code Playgroud)
在执行之前和之后保持RAM使用不变.
我以前的RAM使用问题仅仅是因为中间结果存储为ans.但是,调用whos()后调用OscarTheGrouch()显示没有存储中间数组结果.
我可以重现你的行为
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.3.0 (2014-08-20 20:43 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-apple-darwin13.3.0
julia> # Memory now about 64M
julia> A = rand(Float32, 20000, 20000);
julia> # Memory now about 1600M
julia> A = 0
0
julia> gc()
julia> # Memory now about 75M
julia> function test1()
A = rand(Float32, 20000, 20000)
nothing
end
test1 (generic function with 1 method)
julia> test1() # Still about 78, although briefly higher
julia> function test2()
A = rand(Float32, 20000, 20000)
A = 0
end
test2 (generic function with 1 method)
julia> test2() # Same behaviour
0
julia> function test3()
A = rand(Float32, 20000, 20000)
A = 0
gc()
end
test3 (generic function with 1 method)
julia> test3() # Now at 1600M
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
985 次 |
| 最近记录: |