Stream: helpdesk (published)

Topic: ✔ Checking memory usage


view this post on Zulip Rasmus Henningsson (Apr 29 2026 at 08:28):

Is there any reliable way to probe the amount of memory available for allocation? Sys.free_memory() is not enough, because if I understand things correctly, Julia's GC can keep memory around that is available for allocation within the Julia process, but not available for the OS.

I've tried to make an MVE to investigate this:

julia> using Random

julia> Base.format_bytes(Sys.free_memory())
"58.672 GiB"

julia> v = [zeros(UInt8, 50_000) for i in 1:400_000]; # Alloc many chunks

julia> v = v[randperm(length(v))[1:40_000]]; # Keep some random chunks

julia> Base.format_bytes(Sys.free_memory())
"39.935 GiB"

julia> GC.gc(true)

julia> Base.format_bytes(Sys.free_memory())
"39.935 GiB"

julia> Base.format_bytes(Base.summarysize(v))
"1.864 GiB"

julia> v = nothing

julia> GC.gc(true)

julia> Base.format_bytes(Sys.free_memory())
"41.208 GiB"

For some reason, Julia doesn't return the memory to the system, even though I've removed everything I've allocated. I'm fine with that. :slight_smile: But I would like to check how much memory that Julia has claimed and I cannot find any function for doing that.

view this post on Zulip Jakob Nybo Andersen (Apr 29 2026 at 12:42):

I don't think Julia has functionality for that. I would imagine that information is in the system malloc implementation.

view this post on Zulip Rasmus Henningsson (Apr 29 2026 at 13:30):

Ah, I see. So maybe I could ask the system somehow how much memory the Julia process uses and subtract Base.gc_live_bytes() from that.
It wouldn't be perfect either, because any malloc call not tracked by the GC would be counted incorrectly.

view this post on Zulip Notification Bot (Apr 29 2026 at 19:01):

Rasmus Henningsson has marked this topic as resolved.

view this post on Zulip Mark Kittisopikul (Apr 29 2026 at 19:41):

My experience with this is that it can be very platform specific. For example, if you are using HPC, it might be better to ask the scheduler rather than the system.


Last updated: May 13 2026 at 07:35 UTC