<html><head></head><body><div>Hi,</div><div><br></div><blockquote type="cite"><div dir="ltr"><div><span style="font-size:12.8px"> Indeed you suggestion is correct and further reduced the memory leak problem. For some reason I was not able to delete the objects created by "new" at the end of the function, as this caused the program to crash.</span></div></div></blockquote><div><br></div><div>My guess is that you probably deleted them in a wrong order. For example, IloRange stores a reference to 'env' and may want to access it on destruction. Thus, it will cause problems if you deconstruct 'env' before deleting the IloRange object.</div><div><br></div><blockquote type="cite"><div dir="ltr"><div><span style="font-size:12.8px"> So, I replaced this line with: </span></div><div>Graph::ArcMap<IloRange> capacityConstraints(network, IloRange(env, 0 , 0));</div><div>and did the same for other similar lines found in the code.</div></div></blockquote><div><br></div><div>It is a good idea in general to avoid using 'new' whenever possible.</div><div>Amongst other, you will have no problems with memory leaks, and with the problem I described above.</div><div><br></div><blockquote type="cite"><div dir="ltr"><div>However, what solved the problem almost completely is the addition of the command</div><div>env.end();</div></div></blockquote><blockquote type="cite"><div dir="ltr"><div>before the function returns.</div></div></blockquote><div><br></div><div>Well, CPLEX - contrary to LEMON - does not have a proper C++-style memory management. You have to do it manually.</div><div><br></div><blockquote type="cite"><div dir="ltr"><div> (the remaining memory leaks were caused by the objects of a Class defined in our code which did not have a proper destructor defined).</div></div></blockquote><div><br></div><div>Once again - use the standard stl containers (std::vectors, std::lists etc) instead of manual memory management. Then your destructor will be empty in most of the cases. It's very difficult to make a mistake in implementing an empty destructor.</div><div><br></div><blockquote type="cite"><div dir="ltr"><div>I am wondering if it is a good practice to create and end the CPLEX env within a function, or it is better to create it jut once in main. Then the command env.end() might not be needed at all.</div></div></blockquote><div><br></div><div>Probably it's much better to do it only once.</div><div><br></div><div>Regards,</div><div>Alpár</div></body></html>