Hi <br><br>I noticed that there were some questions about memory leaks in coin LP in the mailing list archive.<br>I sent a similar questions to coin util but without any answer.<br>I post again the message i left one month ago at coin util mailing list.
<br>Sincerely yours<br><br>Xavier Warin<br><br><br>Hi<br><br>I 'm a new user of coin Clp. I 'm moving from Lpsolve to coin which is far more effective (a factor 4 for my application)<br>I use Osi-0.96.1<br>But in my application which uses a big number of linear problems to solve i faced some problems of memory leaks with Coin.
<br>I went back to the build.cpp Osi example that i slightly modified adding delete.<br><br>// Example of using COIN-OR OSI, building the instance internally<br>// with sparse matrix object<br><br>#include <iostream>
<br>#include "OsiClpSolverInterface.hpp"<br>#include "CoinPackedMatrix.hpp"<br>#include "CoinPackedVector.hpp"<br><br>int<br>main(void)<br>{<br> // Create a problem pointer. We use the base class here.
<br> OsiSolverInterface *si;<br><br> // When we instantiate the object, we need a specific derived class.<br> si = new OsiClpSolverInterface; <br><br> // Build our own instance from scratch<br><br> /*<br> * This section adapted from Matt Galati's example
<br> * on the COIN-OR Tutorial website.<br> *<br> * Problem from Bertsimas, Tsitsiklis page 21<br> * <br> * optimal solution: x* = (1,1)<br> * <br> * minimize -1 x0 - 1 x1<br> * s.t 1 x0 + 2 x1 <= 3
<br> * 2 x0 + 1 x1 <= 3<br> * x0 >= 0<br> * x1 >= 0<br> */<br><br> int n_cols = 2;<br> double *objective = new double[n_cols];//the objective coefficients
<br> double *col_lb = new double[n_cols];//the column lower bounds<br> double *col_ub = new double[n_cols];//the column upper bounds<br><br> //Define the objective coefficients.<br> //minimize -1 x0 - 1 x1
<br> objective[0] = -1.0;<br> objective[1] = -1.0;<br><br> //Define the variable lower/upper bounds.<br> // x0 >= 0 => 0 <= x0 <= infinity<br> // x1 >= 0 => 0 <= x1 <= infinity<br>
col_lb[0] =
0.0;<br> col_lb[1] = 0.0;<br> col_ub[0] = si->getInfinity();<br> col_ub[1] = si->getInfinity();<br> <br> int n_rows = 2;<br> double *row_lb = new double[n_rows]; //the row lower bounds<br> double *row_ub = new double[n_rows]; //the row upper bounds
<br> <br> //Define the constraint matrix.<br> CoinPackedMatrix *matrix = new CoinPackedMatrix(false,0,0);<br> matrix->setDimensions(0, n_cols);<br><br> //1 x0 + 2 x1 <= 3 => -infinity <= 1 x0 + 2 x2 <= 3
<br> CoinPackedVector row1;<br> row1.insert(0, 1.0);<br> row1.insert(1, 2.0);<br> row_lb[0] = -1.0 * si->getInfinity();<br> row_ub[0] = 3.0;<br> matrix->appendRow(row1);<br><br> //2 x0 + 1 x1 <= 3 => -infinity <= 2 x0 + 1 x1 <= 3
<br> CoinPackedVector row2;<br> row2.insert(0, 2.0);<br> row2.insert(1, 1.0);<br> row_lb[1] = -1.0 * si->getInfinity();<br> row_ub[1] = 3.0;<br> matrix->appendRow(row2);<br><br> //load the problem to OSI
<br> si->loadProblem(*matrix, col_lb, col_ub, objective, row_lb, row_ub);<br><br> //write the MPS file to a file called example.mps<br> si->writeMps("example");<br><br> <br><br> // Solve the (relaxation of the) problem
<br> si->initialSolve();<br><br> // Check the solution<br> if ( si->isProvenOptimal() ) { <br> std::cout << "Found optimal solution!" << std::endl; <br> std::cout << "Objective value is " << si->getObjValue() << std::endl;
<br><br> int n = si->getNumCols();<br> const double *solution;<br> solution = si->getColSolution();<br> // We could then print the solution or examine it.<br> } else {<br> std::cout << "Didn't find optimal solution." << std::endl;
<br> // Could then check other status functions.<br> }<br><br> delete si, matrix;<br> delete [] row_lb;<br> delete [] row_ub;<br> delete [] col_lb;<br> delete [] col_ub ;<br> delete [] objective ;<br> return 0;
<br>}<br><br>I used valgrind that gave me the following results :<br>==11412==<br>==11412== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 27 from 1)<br>==11412== malloc/free: in use at exit: 128 bytes in 5 blocks.
<br>==11412== malloc/free: 1,427 allocs, 1,422 frees, 1,456,883 bytes allocated.<br>==11412== For counts of detected errors, rerun with: -v<br>==11412== searching for pointers to 5 not-freed blocks.<br>==11412== checked 146,200 bytes.
<br>==11412==<br>==11412==<br>==11412== 8 bytes in 1 blocks are indirectly lost in loss record 1 of 5<br>==11412== at 0x401D7C1: operator new[](unsigned) (vg_replace_malloc.c:195)<br>==11412== by 0x4238D2E: CoinPackedMatrix::resizeForAddi
<div id="mb_0">ngMajorVectors(int, int const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412== by 0x423B5DB: CoinPackedMatrix::appendMajorVector(int, int const*, double const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412== by 0x423B674: CoinPackedMatrix::appendMajorVector(CoinPackedVectorBase const&) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412== by 0x423B6CB: CoinPackedMatrix::appendRow(CoinPackedVectorBase const&) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412== by 0x43C1EA7: (below main) (in /lib/tls/i686/cmov/libc-<a href="http://2.3.6.so/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
2.3.6.so</a>)<br>==11412==<br>==11412==<br>==11412== 12 bytes in 1 blocks are indirectly lost in loss record 2 of 5<br>==11412== at 0x401D7C1: operator new[](unsigned) (vg_replace_malloc.c:195)<br>==11412== by 0x4238D1C: CoinPackedMatrix::resizeForAddingMajorVectors(int, int const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412== by 0x423B5DB: CoinPackedMatrix::appendMajorVector(int, int const*, double const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412== by 0x423B674: CoinPackedMatrix::appendMajorVector(CoinPackedVectorBase const&) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412== by 0x423B6CB: CoinPackedMatrix::appendRow(CoinPackedVectorBase const&) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412== by 0x43C1EA7: (below main) (in /lib/tls/i686/cmov/libc-<a href="http://2.3.6.so/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
2.3.6.so</a>)<br>==11412==<br>==11412==<br>==11412== 16 bytes in 1 blocks are indirectly lost in loss record 3 of 5<br>==11412== at 0x401D7C1: operator new[](unsigned) (vg_replace_malloc.c:195)<br>==11412== by 0x4238E07: CoinPackedMatrix::resizeForAddingMajorVectors(int, int const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412== by 0x423B5DB: CoinPackedMatrix::appendMajorVector(int, int const*, double const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412== by 0x423B674: CoinPackedMatrix::appendMajorVector(CoinPackedVectorBase const&) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412== by 0x423B6CB: CoinPackedMatrix::appendRow(CoinPackedVectorBase const&) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412== by 0x43C1EA7: (below main) (in /lib/tls/i686/cmov/libc-<a href="http://2.3.6.so/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
2.3.6.so</a>)<br>==11412==<br>==11412==<br>==11412== 32 bytes in 1 blocks are indirectly lost in loss record 4 of 5<br>==11412== at 0x401D7C1: operator new[](unsigned) (vg_replace_malloc.c:195)<br>==11412== by 0x4238E19: CoinPackedMatrix::resizeForAddingMajorVectors(int, int const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412== by 0x423B5DB: CoinPackedMatrix::appendMajorVector(int, int const*, double const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412== by 0x423B674: CoinPackedMatrix::appendMajorVector(CoinPackedVectorBase const&) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412== by 0x423B6CB: CoinPackedMatrix::appendRow(CoinPackedVectorBase const&) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412== by 0x43C1EA7: (below main) (in /lib/tls/i686/cmov/libc-<a href="http://2.3.6.so/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
2.3.6.so</a>)<br>==11412==<br>==11412==<br>==11412== 128 (60 direct, 68 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5<br>==11412== at 0x401DB31: operator new(unsigned) (vg_replace_malloc.c:163)
<br>
==11412== by 0x8048CCD: main (build.cpp:58)<br>==11412==<br>==11412== LEAK SUMMARY:<br>==11412== definitely lost: 60 bytes in 1 blocks.<br>==11412== indirectly lost: 68 bytes in 4 blocks.<br>==11412== possibly lost: 0 bytes in 0 blocks.
<br>==11412== still reachable: 0 bytes in 0 blocks.<br>==11412== suppressed: 0 bytes in 0 blocks.<br><br>Is it a bug or a my mistake. <br><br>Sincerely yours</div>