Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Memory leak in CPLEX?

    Posted Mon August 30, 2010 02:37 AM

    Originally posted by: zoldfish


    I am using Concert Technology, C++

    When I am using Cplex, I find that the following codes seem to cause memory leak:

    #include <ilcplex/ilocplex.h>
     
    ILOSTLBEGIN
     
    int main(int argc, char **argv) 
    {
            IloEnv env;
            try 
            {
                    IloNumVar x(env);
                    IloInt n=0;
                    while (1)
                    {
                            IloExpr expr(env);
                            expr=x;
                            expr.end();
                            n++;
                            if (env.getMemoryUsage() > 500e6) {
                            
                                    cout<<"Memory useage; "<<env.getMemoryUsage()<<endl;
                                    cout<<"Number of loops is "<<n<<endl;
                                    break;
                            }
                    }
            }
            catch(IloException &e) {
                    cerr  << " ERROR: " << e << endl;  
            }
            catch(...) {
                    cerr  << " ERROR" << endl;   
            }
            return 0;
    }
    


    When IloExpr instance is established and then end method is called to release this instance, the memory it used seems not be released and memory will soon be used up. I think this is quite a severe problem so I wonder if this is Cplex's problem or mine.

    Thanks a lot~!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Memory leak in CPLEX?

    Posted Mon August 30, 2010 03:44 AM

    Originally posted by: SystemAdmin


    I think it is your fault. The problem is this:
    IloExpr expr(env);
    expr = x;
    

    The first line creates a new IloExprI instance and makes expr a reference to that.
    The second line makes expr reference the same expression that is referenced by x, thereby dropping the reference to the IloExprI instance created in the first line.
    There are three versions to do things correctly:
    // Version 1
    IloExpr expr = x;
     
    // Version 2
    IloExpr expr;
    expr = x;
     
    // Version 3
    IloExpr expr(env);
    expr += x;
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Memory leak in CPLEX?

    Posted Mon August 30, 2010 05:03 AM

    Originally posted by: zoldfish


    > dju358 wrote:
    > I think it is your fault. The problem is this:
    >
    > IloExpr expr(env);
    > expr = x;
    >
    

    > The first line creates a new IloExprI instance and makes expr a reference to that.
    > The second line makes expr reference the same expression that is referenced by x, thereby dropping the reference to the IloExprI instance created in the first line.
    > There are three versions to do things correctly:
    >
    > // Version 1
    > IloExpr expr = x;
    > 
    > // Version 2
    > IloExpr expr;
    > expr = x;
    > 
    > // Version 3
    > IloExpr expr(env);
    > expr += x;
    >
    


    Thanks a lot, that really works. My understanding about CPLEX needs to be corrected...
    However when I am using IloRangeArray instance additionally, another similar problem comes out. I post a new thread Here . I will appreciate much if you can help me again there~thanks!
    #CPLEXOptimizers
    #DecisionOptimization