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 &#39;m a new user of coin Clp. I &#39;m moving from Lpsolve to coin which is far more effective (a factor 4&nbsp; 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&nbsp; Osi example&nbsp; that i slightly modified&nbsp; adding delete.<br><br>// Example of using COIN-OR OSI, building the instance internally<br>// with sparse matrix object<br><br>#include &lt;iostream&gt;
<br>#include &quot;OsiClpSolverInterface.hpp&quot;<br>#include &quot;CoinPackedMatrix.hpp&quot;<br>#include &quot;CoinPackedVector.hpp&quot;<br><br>int<br>main(void)<br>{<br>&nbsp;&nbsp; // Create a problem pointer.&nbsp; We use the base class here.
<br>&nbsp;&nbsp; OsiSolverInterface *si;<br><br>&nbsp;&nbsp; // When we instantiate the object, we need a specific derived class.<br>&nbsp;&nbsp; si = new OsiClpSolverInterface;&nbsp; <br><br>&nbsp;&nbsp; // Build our own instance from scratch<br><br>&nbsp;&nbsp; /*<br>&nbsp;&nbsp;&nbsp; * This section adapted from Matt Galati&#39;s example 
<br>&nbsp;&nbsp;&nbsp; * on the COIN-OR Tutorial website.<br>&nbsp;&nbsp;&nbsp; *<br>&nbsp;&nbsp;&nbsp; * Problem from Bertsimas, Tsitsiklis page 21<br>&nbsp;&nbsp;&nbsp; *&nbsp; <br>&nbsp;&nbsp;&nbsp; *&nbsp; optimal solution: x* = (1,1)<br>&nbsp;&nbsp;&nbsp; *&nbsp; <br>&nbsp;&nbsp;&nbsp; *&nbsp; minimize -1 x0 - 1 x1<br>&nbsp;&nbsp;&nbsp; *&nbsp; s.t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 x0 + 2 x1 &lt;= 3
<br>&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 x0 + 1 x1 &lt;= 3<br>&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;= 0<br>&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;= 0<br>&nbsp;&nbsp;&nbsp; */<br><br>&nbsp;&nbsp; int n_cols = 2;<br>&nbsp;&nbsp; double *objective&nbsp;&nbsp;&nbsp; = new double[n_cols];//the objective coefficients
<br>&nbsp;&nbsp; double *col_lb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = new double[n_cols];//the column lower bounds<br>&nbsp;&nbsp; double *col_ub&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = new double[n_cols];//the column upper bounds<br><br>&nbsp;&nbsp; //Define the objective coefficients.<br>&nbsp;&nbsp; //minimize -1 x0 - 1 x1
<br>&nbsp;&nbsp; objective[0] = -1.0;<br>&nbsp;&nbsp; objective[1] = -1.0;<br><br>&nbsp;&nbsp; //Define the variable lower/upper bounds.<br>&nbsp;&nbsp; // x0 &gt;= 0&nbsp;&nbsp; =&gt;&nbsp; 0 &lt;= x0 &lt;= infinity<br>&nbsp;&nbsp; // x1 &gt;= 0&nbsp;&nbsp; =&gt;&nbsp; 0 &lt;= x1 &lt;= infinity<br>
&nbsp;&nbsp; col_lb[0] = 
0.0;<br>&nbsp;&nbsp; col_lb[1] = 0.0;<br>&nbsp;&nbsp; col_ub[0] = si-&gt;getInfinity();<br>&nbsp;&nbsp; col_ub[1] = si-&gt;getInfinity();<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; int n_rows = 2;<br>&nbsp;&nbsp; double *row_lb = new double[n_rows]; //the row lower bounds<br>&nbsp;&nbsp; double *row_ub = new double[n_rows]; //the row upper bounds
<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; //Define the constraint matrix.<br>&nbsp;&nbsp; CoinPackedMatrix *matrix =&nbsp; new CoinPackedMatrix(false,0,0);<br>&nbsp;&nbsp; matrix-&gt;setDimensions(0, n_cols);<br><br>&nbsp;&nbsp; //1 x0 + 2 x1 &lt;= 3&nbsp; =&gt;&nbsp; -infinity &lt;= 1 x0 + 2 x2 &lt;= 3
<br>&nbsp;&nbsp; CoinPackedVector row1;<br>&nbsp;&nbsp; row1.insert(0, 1.0);<br>&nbsp;&nbsp; row1.insert(1, 2.0);<br>&nbsp;&nbsp; row_lb[0] = -1.0 * si-&gt;getInfinity();<br>&nbsp;&nbsp; row_ub[0] = 3.0;<br>&nbsp;&nbsp; matrix-&gt;appendRow(row1);<br><br>&nbsp;&nbsp; //2 x0 + 1 x1 &lt;= 3&nbsp; =&gt;&nbsp; -infinity &lt;= 2 x0 + 1 x1 &lt;= 3
<br>&nbsp;&nbsp; CoinPackedVector row2;<br>&nbsp;&nbsp; row2.insert(0, 2.0);<br>&nbsp;&nbsp; row2.insert(1, 1.0);<br>&nbsp;&nbsp; row_lb[1] = -1.0 * si-&gt;getInfinity();<br>&nbsp;&nbsp; row_ub[1] = 3.0;<br>&nbsp;&nbsp; matrix-&gt;appendRow(row2);<br><br>&nbsp;&nbsp; //load the problem to OSI
<br>&nbsp;&nbsp; si-&gt;loadProblem(*matrix, col_lb, col_ub, objective, row_lb, row_ub);<br><br>&nbsp;&nbsp; //write the MPS file to a file called example.mps<br>&nbsp;&nbsp; si-&gt;writeMps(&quot;example&quot;);<br><br>&nbsp; <br><br>&nbsp;&nbsp; // Solve the (relaxation of the) problem
<br>&nbsp;&nbsp; si-&gt;initialSolve();<br><br>&nbsp;&nbsp; // Check the solution<br>&nbsp;&nbsp; if ( si-&gt;isProvenOptimal() ) { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Found optimal solution!&quot; &lt;&lt; std::endl; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Objective value is &quot; &lt;&lt; si-&gt;getObjValue() &lt;&lt; std::endl;
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int n = si-&gt;getNumCols();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const double *solution;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; solution = si-&gt;getColSolution();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // We could then print the solution or examine it.<br>&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Didn&#39;t find optimal solution.&quot; &lt;&lt; std::endl;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Could then check other status functions.<br>&nbsp;&nbsp; }<br><br>&nbsp;&nbsp; delete si, matrix;<br>&nbsp;&nbsp; delete [] row_lb;<br>&nbsp;&nbsp; delete [] row_ub;<br>&nbsp;&nbsp; delete [] col_lb;<br>&nbsp;&nbsp; delete [] col_ub ;<br>&nbsp;&nbsp; delete [] objective ;<br>&nbsp;&nbsp; return 0;
<br>}<br><br>I used valgrind that gave me&nbsp; 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==&nbsp;&nbsp;&nbsp; at 0x401D7C1: operator new[](unsigned) (vg_replace_malloc.c:195)<br>==11412==&nbsp;&nbsp;&nbsp; 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==&nbsp;&nbsp;&nbsp; by 0x423B5DB: CoinPackedMatrix::appendMajorVector(int, int const*, double const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B674: CoinPackedMatrix::appendMajorVector(CoinPackedVectorBase const&amp;) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B6CB: CoinPackedMatrix::appendRow(CoinPackedVectorBase const&amp;) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412==&nbsp;&nbsp;&nbsp; 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==&nbsp;&nbsp;&nbsp; at 0x401D7C1: operator new[](unsigned) (vg_replace_malloc.c:195)<br>==11412==&nbsp;&nbsp;&nbsp; by 0x4238D1C: CoinPackedMatrix::resizeForAddingMajorVectors(int, int const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B5DB: CoinPackedMatrix::appendMajorVector(int, int const*, double const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B674: CoinPackedMatrix::appendMajorVector(CoinPackedVectorBase const&amp;) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B6CB: CoinPackedMatrix::appendRow(CoinPackedVectorBase const&amp;) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412==&nbsp;&nbsp;&nbsp; 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==&nbsp;&nbsp;&nbsp; at 0x401D7C1: operator new[](unsigned) (vg_replace_malloc.c:195)<br>==11412==&nbsp;&nbsp;&nbsp; by 0x4238E07: CoinPackedMatrix::resizeForAddingMajorVectors(int, int const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B5DB: CoinPackedMatrix::appendMajorVector(int, int const*, double const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B674: CoinPackedMatrix::appendMajorVector(CoinPackedVectorBase const&amp;) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B6CB: CoinPackedMatrix::appendRow(CoinPackedVectorBase const&amp;) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412==&nbsp;&nbsp;&nbsp; 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==&nbsp;&nbsp;&nbsp; at 0x401D7C1: operator new[](unsigned) (vg_replace_malloc.c:195)<br>==11412==&nbsp;&nbsp;&nbsp; by 0x4238E19: CoinPackedMatrix::resizeForAddingMajorVectors(int, int const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B5DB: CoinPackedMatrix::appendMajorVector(int, int const*, double const*) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B674: CoinPackedMatrix::appendMajorVector(CoinPackedVectorBase const&amp;) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)
<br>==11412==&nbsp;&nbsp;&nbsp; by 0x423B6CB: CoinPackedMatrix::appendRow(CoinPackedVectorBase const&amp;) (in /home/warin/LOGICIEL_4.1/lib/libCoinUtils.so.0.0.0)<br>==11412==&nbsp;&nbsp;&nbsp; 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==&nbsp;&nbsp;&nbsp; at 0x401DB31: operator new(unsigned) (vg_replace_malloc.c:163)
<br>
==11412==&nbsp;&nbsp;&nbsp; by 0x8048CCD: main (build.cpp:58)<br>==11412==<br>==11412== LEAK SUMMARY:<br>==11412==&nbsp;&nbsp;&nbsp; definitely lost: 60 bytes in 1 blocks.<br>==11412==&nbsp;&nbsp;&nbsp; indirectly lost: 68 bytes in 4 blocks.<br>==11412==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; possibly lost: 0 bytes in 0 blocks.
<br>==11412==&nbsp;&nbsp;&nbsp; still reachable: 0 bytes in 0 blocks.<br>==11412==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; suppressed: 0 bytes in 0 blocks.<br><br>Is it a bug or a my mistake. <br><br>Sincerely yours</div>