Skip to content
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

memory leak in jl_() #9767

Closed
yuyichao opened this issue Jan 14, 2015 · 12 comments
Closed

memory leak in jl_() #9767

yuyichao opened this issue Jan 14, 2015 · 12 comments

Comments

@yuyichao
Copy link
Contributor

Warning: don't try it on a system with small memory

function f(n, x)
    for i in 1:n
        ccall(:jl_, Void, (Any,), (i, n, x))
    end
end
f(1000000, "")

The script above consumes 1.5G memory on my laptop. Calling gc does not release the memory. Replacing :ccall(jl_) with println solves the problem.

WARNING: Again, the memory comsumption is roughly linear with n, don't run the script unless you have enough memory or you've setup a ulimit on it. The script cannot be killed with Ctrl-C but you can interrupt it with Ctrl-\

@yuyichao
Copy link
Contributor Author

Reproducible with master and 0.3.5

@vtjnash
Copy link
Member

vtjnash commented Jan 14, 2015

the system (julia) needs to enter the event loop at some point in time to finalize the write buffers. does calling yield help?

@yuyichao
Copy link
Contributor Author

Let met try. calling gc afterword in REPL doesn't help though.

@yuyichao
Copy link
Contributor Author

Adding yield() right after the ccall solves the problem..... However, if the memory is already allocated, nothing can free it....

@JeffBezanson
Copy link
Member

jl_ is only for debugging, so this is quasi-acceptable. Though we could maybe add a call to run_once (or whichever) at the end of jl_.

@Keno
Copy link
Member

Keno commented Jan 14, 2015

The even better solution would be to get libuv to call the write completion callback immediately if the buffer is no longer needed.

@vtjnash
Copy link
Member

vtjnash commented Jan 14, 2015

Libuv provides an explicit guarantee that it will never execute a callback in the middle of running user code. I don't think they are interested in undoing that work.

@Keno
Copy link
Member

Keno commented Jan 14, 2015

Well, they could add a return code that indicates that the write succeeded synchronously and no callback will be delivered.

@vtjnash
Copy link
Member

vtjnash commented Jan 14, 2015

uv_run executes arbitrary callbacks, which runs somewhat counter to the design and purpose of jl_ as a dead simple function for use from gdb or analyzing bootstrapping failures and does not affect Julia state

@JeffBezanson
Copy link
Member

I agree; this is just a debugging function. It is really not worth putting any effort into this.

@ivarne ivarne added the won't change Indicates that work won't continue on an issue or pull request label Jan 21, 2015
@yuyichao
Copy link
Contributor Author

FWIW, this seems to be fixed in master....

@yuyichao yuyichao removed the won't change Indicates that work won't continue on an issue or pull request label Jun 23, 2015
@vtjnash
Copy link
Member

vtjnash commented Jun 23, 2015

good point. at some point, i switched it to write directly stderr so that it wouldn't need to impact the julia structures (like memory)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants