Hi, Tim<br><br>Thanks for fixing the leak. I spent sometime to look at the kinds of mem leaks Flopc++ has, and it seems that not all leaks are caused by MP_domain.hpp. Many can be traced to pointers returned by a method call, and the caller never deletes these pointers afterward. For instance, in "mp_model.cpp", call getDefaultModel() returns a pointer to MP_model(0), but it is never deleted.
<br>-------------------------<br>MP_model& MP_model::default_model = *new MP_model(0);<br>MP_model* MP_model::current_model = &MP_model::default_model;<br>MP_model &MP_model::getDefaultModel() { return default_model;}
<br>MP_model *MP_model::getCurrentModel() { return current_model;}<br>-----------------------<br><br>Similar patterns can be found in other places. In "mp_constant.cpp",<br>---------------------------<br> Constant::Constant(double d) :
<br> Handle<Constant_base*>(new Constant_double(d)) {}<br>--------------------------<br>Constant(d) returns a pointer to Constant_double(d), and it is never deleted by its caller. <br><br>I guess it may require a major overhaul to fix all these leaks as there are many methods return pointers to some newed classes.
<br><br>Cheers<br>Paul<br><br><br><br><br><br><br><div><span class="gmail_quote">On 5/20/07, <b class="gmail_sendername">Tim Hultberg</b> <<a href="mailto:Tim.Hultberg@eumetsat.int">Tim.Hultberg@eumetsat.int</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi, Paul<br><br>yes this one is just as easy as you say. I have fixed it now in<br>stable/1.0.
<br><br>[if you find more easy ones, let me know :-)]<br><br>The remaining leaks (I am aware of) comes from some limitations in the<br>current implementation of MP_domain. I have a leak free implementation<br>of it in branches/experiment/experiment/New_domain.hpp but I have never
<br>had the time to integrate it properly.<br><br>Cheers, Tim<br><br>Tim Hultberg<br><br>>>> "Paul Huang" <<a href="mailto:huangpaul99@gmail.com">huangpaul99@gmail.com</a>> 05/18/07 9:33 PM >>>
<br>Hi, Tim<br><br>I understand you know FlopC++ has quite a few memory leaks. Some are<br>minor<br>but some are significant. After checking the source code, I assume,<br>based on<br>my limited understanding, some leaks are easy to fix. For example, in
<br>mp_model.cpp, a pointer c is newed and passed to "Solver->loadProblem"<br>but<br>never released. Here is the code<br><br>---------------------------------------------------<br>c = new double[n];<br> for (int j=0; j<n; j++) {
<br> c[j] = 0.0;<br> }<br> for (size_t i=0; i<coefs.size(); i++) {<br> int col = coefs[i].col;<br> double elm = coefs[i].val;<br> c[col] = elm;<br> }<br><br> // Column bounds<br> for (int j=0; j<n; j++) {
<br> l[j] = 0.0;<br> u[j] = inf;<br> }<br><br> for (varIt i=Variables.begin(); i!=Variables.end(); i++) {<br> for (int k=0; k<(*i)->size(); k++) {<br> l[(*i)->offset+k] = (*i)->lowerLimit.v[k];
<br> u[(*i)->offset+k] = (*i)->upperLimit.v[k];<br> }<br> }<br><br> Solver->loadProblem(n, m, Cst, Rnr, Elm, l, u, c, bl, bu);<br>-----------------------------------------------<br><br>My question is, is it just as easy as add "delete [] c" after calling
<br>"Solver->loadProblem" and then the problem will be fixed, or it is not<br>as<br>easy as it looks and more complication is involved? If the former is<br>true,<br>then my second question is, when are you going to fix those easy-to-fix
<br>leaks? :-)<br><br><br>Cheers<br>Paul<br><br></blockquote></div><br>