Skip to content

Avoid retaining evaluate out arrays#560

Open
gaoflow wants to merge 1 commit into
pydata:masterfrom
gaoflow:fix-558-out-cache-weakref
Open

Avoid retaining evaluate out arrays#560
gaoflow wants to merge 1 commit into
pydata:masterfrom
gaoflow:fix-558-out-cache-weakref

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 19, 2026

Copy link
Copy Markdown

Fixes #558.

validate() cached the out= array directly in _numexpr_last so re_evaluate() could reuse it. That kept the most recent output array alive even after the caller deleted their last reference.

This stores a weak reference for cached out= instead. re_evaluate() resolves it when called, so live output arrays are still reused, but released arrays are no longer pinned by the cache.

Tests:

  • .venv/bin/python -m pytest numexpr/tests/test_numexpr.py -q
  • .venv/bin/python -m pytest --pyargs numexpr -q
  • .venv/bin/python -m compileall -q numexpr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

evaluate(..., out=arr) keeps arr pinned in the thread-local _numexpr_last cache

1 participant