-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
MWE (less connection to a database with a large table):
using LibPQ
# This works fine if you run it _before_ doing LibPQ stuff.
# Allocates about 28GB of RAM (fine on my machine if not much else
# is going on. Tailor this to consume lots of memory, but not more
# than you might reasonably have available in a Julia session with
# nothing else going on).
# Note that this function doesn't return anything, so Julia is free
# to use the memory for other stuff once it's run.
function allocate_large_array_less_than_RAM()
x = fill(1.0, 3_500_000_000)
return nothing
end
# Nothing escapes this function, so memory should be available for
# Julia to use once execution is complete.
# The idea is that the amount that this allocates + however much
# allocate_large_array_less_than_RAM allocates should be more than
# the amount of RAM available.
# This ensures that, if the problem is indeed LibPQ failing to free up
# some memory that has been handed over to C, Julia will complain about
# not having enough memory when we run this, followed by
# allocate_large_array_less_than_RAM.
function get_data()
conn = <set-up-connection>
result = execute(
conn,
"SELECT column from large_table;";
binary_format=true,
)
data = LibPQ.columntable(result)
return nothing
end
println("Allocating a large array -- this runs fine before we run get_data")
allocate_large_array_less_than_RAM()
println("Getting lots of data")
get_data()
println("Trying to allocate a large array again. Yields an OutOfMemory error on my machine")
allocate_large_array_less_than_RAM()
# Running get_data 10 times seems to increase memory usage.
# On my machine, this eventually kills my process, and it appears to be
# because memory usage continually increases with each iteration
# (I'm just staring at htop).
for _ in 1:10
get_data()
end
Based on the above, this looks like a memory leak.
For reference, I have 32GB of RAM and 0 swap.
edit: julia 1.7.3, LibPQ 1.13.0
tpgillam
Metadata
Metadata
Assignees
Labels
No labels