I am using the SparseMatrix class of the library Eigen. To create one, I use:
typedef Eigen::SparseMatrix<float> matrix;
matrix M (10,10);
How can I call the destructor of this object ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The clear, obvious, safest, and probably most efficient solution is to just use the normal C++ semantics. “Reinitialization” is done with assignment.
Declare the matrix inside the loop body, and it will be properly initialized and destroyed at every loop iteration.
Oh, and assuming a non-buggy library, there is zero memory leakage in all these cases. Just don’t toss
news around and don’t play with fire (like calling destructors directly).