yig / PySPQR

Python wrapper for the sparse QR decomposition in SuiteSparseQR.
Creative Commons Zero v1.0 Universal
34 stars 28 forks source link

Not all cholmod variables are freed in qr(), _solve_with_sparse_rhs() and _solve_with_dense_rhs() #22

Closed urbi95 closed 1 year ago

urbi95 commented 1 year ago

In the file sparseqr/sparseqr.py, I believe there should be the line cholmod_free_sparse( chol_A ) added at the end of the definition of the function qr() and

cholmod_free_sparse( chol_A )
cholmod_free_dense( chol_b )

at the end of _solve_with_sparse_rhs() and _solve_with_dense_rhs(), respectively. This should free all the cholmod variables used in those functions after they are not needed any more.

The reason I bring this up is that I was running qr() ~1000 times at a time, and my program would always be aborted without an error message. So I was guessing there must be some memory not being freed up. Adding the above fixed my issue. So hopefully this helps others that have the same problem.

Thank you to the maintainers of this repo for sharing your wrapper to SuiteSparseQR! It has helped me immensely.

yig commented 1 year ago

You are right! Thank you. I bumped the version to 1.2.1.

I only see the leak for qr() and rz(). The other functions, _solve_with_sparse_rhs() and _solve_with_dense_rhs(), already have those lines.