Explicit GC.gc call does not reclaim memory on 1.11 and master #54020
Description
Here is a simple setup that makes julia memory leak until it is killed by the OS (x86 linux, glibc), on a single thread:
function bar(n)
x = [collect(1:n) for _ in 1:(900_000_000÷n)]
first(last(x))
end
I have 8 GiB of RAM available after executing the above. Calling bar(n)
once uses around 6.7GiB for any value of n
between 1000 and 100_000. That's fine, and this memory used to create and fill x
should be reclaimable by GC. But calling bar(n)
a second time then crashes julia, even if the two calls are separated by GC.gc(false); GC.gc(true)
. This occurs on v1.11.0-alpha2 and master (d183ee1), but not on 1.10.2.
liozou@liozou:~$ julia-master/usr/bin/julia -t1 --startup-file=no -E 'bar(n) = (x = [collect(1:n) for _ in 1:(900_000_000÷n)]; first(last(x))); bar(9000);' # master: one call is fine
1
liozou@liozou:~$ julia-master/usr/bin/julia -t1 --startup-file=no -E 'bar(n) = (x = [collect(1:n) for _ in 1:(900_000_000÷n)]; first(last(x))); bar(9000); GC.gc(false); GC.gc(true); bar(9000)' # master: two calls crash
Killed
liozou@liozou:~$ julia-1.11.0-alpha2/bin/julia -t1 --startup-file=no -E 'bar(n) = (x = [collect(1:n) for _ in 1:(900_000_000÷n)]; first(last(x))); bar(9000);' # v1.11: one call is fine
1
liozou@liozou:~$ julia-1.11.0-alpha2/bin/julia -t1 --startup-file=no -E 'bar(n) = (x = [collect(1:n) for _ in 1:(900_000_000÷n)]; first(last(x))); bar(9000); GC.gc(false); GC.gc(true); bar(9000)' # v1.11: two calls crash
Killed
liozou@liozou:~$ julia-1.10.2/bin/julia -t1 --startup-file=no -E 'bar(n) = (x = [collect(1:n) for _ in 1:(900_000_000÷n)]; first(last(x))); bar(9000); bar(9000)' # v1.10 is fine even with two calls
1
(for the sake of completeness, this also used to work on v1.6.6 and v1.7.3, it crashed on v1.8.5 unless an explicit GC.gc()
was called between the two bar(9000)
, and it crashed on v1.9.4 which might be related to #50345)
Irrespective of it being a regression without calling GC.gc
, the fact that an explicit GC.gc
call does not reclaim the free memory looks like a bug to me. See also #51818, but here function bar
exited before the call to GC.gc
.
Activity