Remove unnecessary Py_INCREF in PyBuffer causing memory leak

Change-Id: Ic00f1a989b84d36eccf3c7769251303c849921f9
This commit is contained in:
Wes McKinney committed 2017-05-18 18:18:37 -04:00
1 parent 37cdc6e99b
commit 2f90337c5f
2 files changed
+26 -2

No files matched your search

-1
View File
@@ -55,7 +55,6 @@ PyBuffer::PyBuffer(PyObject* obj) : Buffer(nullptr, 0), obj_(nullptr) {
size_ = buffer->len;
capacity_ = buffer->len;
is_mutable_ = false;
Py_INCREF(obj_);
}
}
+26 -1
View File
@@ -21,6 +21,7 @@ import pyarrow as pa
import numpy as np
import memory_profiler
import gc
import io
def leak():
@@ -32,4 +33,28 @@ def leak():
table.to_pandas()
gc.collect()
leak()
# leak()
def leak2():
data = [pa.array(np.concatenate([np.random.randn(100000)] * 10))]
table = pa.Table.from_arrays(data, ['foo'])
while True:
print('calling to_pandas')
print('memory_usage: {0}'.format(memory_profiler.memory_usage()))
df = table.to_pandas()
batch = pa.RecordBatch.from_pandas(df)
sink = io.BytesIO()
writer = pa.RecordBatchFileWriter(sink, batch.schema)
writer.write_batch(batch)
writer.close()
buf_reader = pa.BufferReader(sink.getvalue())
reader = pa.open_file(buf_reader)
reader.read_all()
gc.collect()
leak2()