-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
readall(echo hello
) leaks memory on master and 0.3
#11814
Comments
Could this be related to #9767? I would be quite surprized if the GC doesn't free the memory it owns. |
We |
what OS have you tested this on? |
On for i in 1:1000000
readall(`echo hello`)
i % 1000 == 0 && println(i)
end I could see a linear memory usage increase of the julia process (measured with resident size with no swap) ~ 220 bytes per iteration. |
Also on OS X. |
after running this for 75000 loops, then canceling with ^C, the most interesting thing I seemed to get was:
for reference, on OS X, the size of the malloc objects is:
after 10-20 minutes of running the test on 0.4 OS X, my machine exhibits behavior on the order of yuyichao's results (200-600 bytes/loop) after accomplishing ~50_000 loops. but that's only a net change of 30 MB and is not approaching nowhere near 1.2 GB. |
A much faster way to get the memory leak is function f(n)
for i in 1:n
fd = open("a")
readall(fd)
close(fd)
i % 1000 == 0 && println(i)
end
end Edit: where "a" is an empty file. |
After all this might still be GC related. julia> function f1(n)
for i in 1:n
fd = open("a")
close(fd)
i % 1000 == 0 && println(i)
end
end
f1 (generic function with 1 method)
julia> function f2(n)
for i in 1:n
fd = open("a")
close(fd)
finalize(fd)
i % 1000 == 0 && println(i)
end
end
f2 (generic function with 1 method)
|
@vtjnash, note that the 1.2 GB is on release-0.3. On master, Julia feels the memory pressure as it should so the leak is relatively slow (but still present). |
@hayd You are totally right... Thanks for catching this.... The worse part is that I don't even get a notification for accidentally doing that since it's my own action..... |
The memory leak I saw (which is very likely the one @StefanKarpinski saw but I cannot say for sure) appears to be not IO related. It is reproducible with the following script. The problem goes away if no finalizer is installed or finalizer is manually run. The size of the leak changes if the size of the array changes so I think the array is somehow not free'd. The issue also goes away if I call close2(s) = nothing
function f1(n)
for i in 1:n
s = zeros(UInt8, 152)
finalizer(s, close2)
# finalize(s)
i % 10000 == 0 && println(i)
end
end
f1(6000_000)
sleep(3) @carnaval When I looked at Would this cause them to be promoted to the old gen and takes much longer to be free'd? (Although even then the memory pressure should probably trigger a full collection?) P.S. if the script remind you about |
I should mention that the size of the three finalizer arrays are reasonable although some of them has a pretty big max. This (and the fact that they can be free'd with a full GC) is why I suspect that
Edit: The GDB session above was captrued when it has run ~ |
Isn't println() I/O related? |
There may be two leaks in that case since there was no generation GC on 0.3. |
In another word, the issue I see cannot possibly be the issue that affects 0.3 .... Edit: @StefanKarpinski Your comment pops up right when I type |
Disabling generational GC makes @StefanKarpinski original example worse although it's hard to tell anything from that since the GC might just be not as good as freeing memory in general when generational stuff is disabled. |
@StefanKarpinski Can you check if you can still reproduce this? My minimum example above is currently still leaking (fixed by #13993) but I couldn't reproduce the leak with your code anymore. (I'm printing |
Yes, this seems to be solved. |
The following program leaks memory on 0.3 and 0.4 to varying degrees:
On 0.3 without the
gc()
call is the worst – memory usage grows to 1.2 GB on my machine in a couple of minutes. If you put thegc()
call in then it's much better – indicating that the memory pressure isn't being felt as it should – but there's still a gradual leak. On 0.4 things are better – and memory pressure is felt as it should be even withoutgc()
– but there is still a slow leak.The text was updated successfully, but these errors were encountered: