DenseMatrix.OfRowArrays().LU() Memory Leak
hi, I test the code, and find the memory of pc is continuously growing。 Does I use not correct? thanks.
float[][] a= ...; DenseMatrix matrix= DenseMatrix.OfRowArrays(a);
float[][] b= ...;
for (int i = 0; i < b.Length; i++)
{
DenseVector v = new DenseVector(b[i]);
// Memory Leak
LU
It seems you are factorizing the same matrix in each loop. This will allocate new memory in each iteration creating memory pressure. It's not a memory leak, the memory will be garbage collected. Still it might impact the runtime.
Creating the LU factorization before the loop should solve your problem.
There's also an overload of the Solve method to avoid allocating memory for the result inside the loop. Just allocate your datas vector before the loop and then use
https://github.com/mathnet/mathnet-numerics/blob/e010de79d70f197112cdc86d2e637f5db2968d24/src/Numerics/LinearAlgebra/Single/Factorization/DenseLU.cs#L128-L133