scipy/scipy — pull request #4073 by MechCoder (2014-10-13 14:58:54+00:00)
Title: Delete attributes of MatrixLinearOperator in lsqr.

I'm not sure that this is the right way.When MatrixLinearOperator is called repeatedly on copies, it seems to me that there is a increase in memory. (Though I don't know why)

X = np.random.randn(24000, 2000)
for _ in range(5):
X = np.copy(X)
t = MatrixLinearOperator(X)

If the range of the number is increased, one can see the increase in memory usage. A stopgap is to delete the attributes after every call that seems to work fine.

Sklearn's Ridge solvers use the `lsqr` function and when it is called repeatedly across a cross-validation object, it sometimes blows up the memory. The discussion in https://github.com/scikit-learn/scikit-learn/issues/3762 articulates this.