From 50fde71f1ac0528f40ee216136b33fde41205ef2 Mon Sep 17 00:00:00 2001 From: Allan Haldane Date: Sat, 17 Feb 2018 14:36:49 -0500 Subject: BUG: break cyclic refs in recursive closures Fixes #10620 --- numpy/core/shape_base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'numpy/core/shape_base.py') diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py index 65c3ed00d..319c25088 100644 --- a/numpy/core/shape_base.py +++ b/numpy/core/shape_base.py @@ -446,7 +446,13 @@ def _block(arrays, max_depth, result_ndim): # type(arrays) is not list return atleast_nd(arrays, result_ndim) - return block_recursion(arrays) + try: + return block_recursion(arrays) + finally: + # recursive closures have a cyclic reference to themselves, which + # requires gc to collect (gh-10620). To avoid this problem, for + # performance and PyPy friendliness, we break the cycle: + block_recursion = None def block(arrays): -- cgit v1.2.1