Repository navigation
Closed as duplicate
Description
I’ve encountered a memory issue when reading Parquet files with Pandas using the pyarrow engine. Even though pyarrow.total_allocated_bytes() reports that allocated memory goes back to zero after each function call, the overall process memory (as reported by psutil) keeps increasing significantly over repeated calls.
Steps to Reproduce:
import psutil
import time
import pandas as pd
import gc
import pyarrow as pa
# pa.jemalloc_set_decay_ms(0)
def print_memory_usage():
process = psutil.Process()
mem_info = process.memory_info()
print(f"PA allocated_bytes after function call: {pa.total_allocated_bytes() / 1024 / 1024:.2f} MB")
print(f"Memory Usage: {mem_info.rss / 1024 / 1024:.2f} MB")
def mem_and_time(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
# Print results
print_memory_usage()
print(f"Execution Time: {end_time - start_time:.6f} seconds")
return result
return wrapper
@mem_and_time
def test_func_pandas():
# When using fastparquet, the memory usage is stable:
# df = pd.read_parquet("/Users/test.parquet", engine='fastparquet')
df = pd.read_parquet("/Users/test.parquet", engine='pyarrow')
print(f"PA allocated_bytes inside function call: {pa.total_allocated_bytes() / 1024 / 1024:.2f} MB")
return None
if __name__ == "__main__":
for _ in range(10000):
test_func_pandas()Observe that:
Inside each function call, pyarrow.total_allocated_bytes() reports a large allocation (e.g., ~2646 MB).
After the function call, pyarrow.total_allocated_bytes() resets to 0 MB.
However, the overall process memory usage (as shown by psutil) increases with each iteration.
PA allocated_bytes inside function call: 2646.27 MB
PA allocated_bytes after function call: 0.00 MB
Memory Usage: 3147.12 MB
Execution Time: 0.669164 seconds
PA allocated_bytes inside function call: 2646.27 MB
PA allocated_bytes after function call: 0.00 MB
Memory Usage: 3945.00 MB
Execution Time: 0.623360 seconds
PA allocated_bytes inside function call: 2646.27 MB
PA allocated_bytes after function call: 0.00 MB
Memory Usage: 4494.80 MB
Execution Time: 0.681895 seconds
PA allocated_bytes inside function call: 2646.27 MB
PA allocated_bytes after function call: 0.00 MB
Memory Usage: 4865.27 MB
Execution Time: 0.641056 seconds
...
PA allocated_bytes inside function call: 2646.27 MB
PA allocated_bytes after function call: 0.00 MB
Memory Usage: 6157.64 MB
Execution Time: 0.659480 seconds
Environment:
Python: 3.13.1
Pandas: 2.2.3
PyArrow: 19.0.0
OS: MacOs Sequoia 15.3.1
Component(s)
Python
Reacted by Luqman
Activity
erykoff commentedon Mar 19, 2025
I have encountered what I think is the same major memory leak when reading large parquet files with
pyarrow.parquet.read_table(), no pandas even installed.pyarrow.total_allocated_bytes()reports constant numbers, but the actual memory usage just goes up and up and up.Whatever the problem is appeared between
pyarrow=17(which uses the expected amount of memory and doesn't leak) andpyarrow=18(which leaks like a sieve).This is a major regression.
twkim112 commentedon Mar 24, 2025
@erykoff how do you handle this issue, by using the fastparquet engine or downgrading to version 17?
erykoff commentedon Mar 24, 2025
We use parquet without pandas, so fastparquet isn't an option. Currently pinning back to v17. I'm also trying to come up with a standalone repro for a better bug report.
mthiboust commentedon Apr 8, 2025
I have the same issue with pyarrow v18 and v19, but not with v17 as described here: #45882 (comment)
mthiboust commentedon Apr 9, 2025
After some investigation, it appears that the difference between versions in the memory profile above is explained by the choice of memory allocator:
jemallocby default for v17 vsmimallocfor v18 and v19.Below is a new memory profile with
pyarrow==19.0.1formimallocon the left andjemallocon the right (loop of 5 iteration of parquet file reading).You can set
jemallocas the default memory allocator using:export ARROW_DEFAULT_MEMORY_POOL=jemallocSee:
antareson commentedon Jun 1, 2026
Is this fixed or still an issue in version 24?
Prussian1870 commentedon Jun 2, 2026
I'm having this issue using the CompressedInputStream.
Environment:
Python: 3.10
PyArrow: 21.0.0
OS: windows 10 pro
erykoff commentedon Jun 2, 2026
I have checked with the latest v24 pyarrow and the default memory allocator still fails to release memory. It's possible that it only uses 3x the memory it should rather than growing unbounded. But overriding
ARROW_DEFAULT_MEMORY_POOL=jemallocuses 3x less memory on my large test file and doesn't grow at all (as expected and desired).Prussian1870 commentedon Jun 6, 2026
Thanks for the help. But that didn't work in python 3.10:
os.environ["ARROW_DEFAULT_MEMORY_POOL"]="jemalloc"
I assume the setting can be set at runtime.
Correct?
In the meantime I started using DataFusion v53 and it worked well with no performance degradation and minimal memory usage.
AlenkaF commentedon Jul 1, 2026
There are quite some issues opened on memory leak/memory allocation connected to Arrow and Parquet. I think the best thread to help one understand the topic and to keep open is #44599. I will close others as duplicate. Feel free to comment and I will re-open if we see I was mistaken and the issues are different.