Print

Print


There seems to be a memory leak in the `vector_read` function in the python bindings. To reproduce:

```python
# debug_vector_read.py
import gc
import pyxrootd.client

filename = "root://eospublic.cern.ch//eos/opendata/atlas/OutreachDatasets/2020-01-22/4lep/MC/mc_345060.ggH125_ZZ4lep.4lep.root"

def test():
    f = pyxrootd.client.File()
    res = f.open(filename)
    if not res[0]["ok"]:
        raise IOError(res)
    chunksize = 1024 * 256
    chunks = [(i * chunksize, chunksize) for i in range(5)]
    res = f.vector_read(chunks)
    print(res[0]["message"])
    f.close()

for i in range(20):
    print(i)
    test()
    gc.collect()
```

When running this through [memory-profiler](https://pypi.org/project/memory-profiler/) with

```
mprof run debug_vector_read.py
mprof plot
```

i get this plot:

![memory_leak](https://user-images.githubusercontent.com/3707225/107959356-9a0fa100-6fa3-11eb-9e16-c69291daee81.png)

(Tested with xrootd 5.0.3 from conda-forge)

It seems the problem are these buffers which are never deleted:

https://github.com/xrootd/xrootd/blob/551521ea7368e3b2a4c7964325e2e7e3fe7ce047/bindings/python/src/PyXRootDFile.cc#L611

Not sure if or when it is allowed to delete them, but if i collect the buffers into an array and delete them after the call to `self->file->VectorRead(...)` the memory leak seems to be gone:

![no_memory_leak](https://user-images.githubusercontent.com/3707225/107960086-7862e980-6fa4-11eb-9747-ca95caf70f7d.png)


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/xrootd/xrootd/issues/1400

########################################################################
Use REPLY-ALL to reply to list

To unsubscribe from the XROOTD-DEV list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=XROOTD-DEV&A=1