BUG: Memory leak when using custom accessor #41357
Labels
Accessors
accessor registration mechanism (not .str, .dt, .cat)
ExtensionArray
Extending pandas with custom dtypes or arrays.
Performance
Memory or execution speed performance
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Problem description
When using a custom accessor, memory is not being freed as expected. This appears to be a result of the accessor storing a reference to the dataframe, as demonstrated in the example above.
The output of the example code is included below showing that after deletion of the dataframe without the accessor initialized, there are 0 uncollectible objects, but after deleting the dataframe with the accessor initialized 17 uncollectible objects remain.
For additional context refer to this issue and this pull request.
Note, this problem appears to be solvable by storing a weak reference to the dataframe in the accessor instead, but I am concerned that using that approach could create other issues.
Expected Output
Both example cases above should release the memory used by the dataframe once it is deleted.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2cb9652
python : 3.8.5.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
Version : Darwin Kernel Version 18.7.0: Mon Aug 31 20:53:32 PDT 2020; root:xnu-4903.278.44~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.2.4
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.1
setuptools : 47.1.0
Cython : None
pytest : 6.0.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.04.0
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: