Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Memory error using Cplex 10.1

    Posted 07/09/08 08:45 PM

    Originally posted by: SystemAdmin


    [Sylvain said:]

    I'm having some memory troubles in using callbacks.
    I'm using Ilog Cplex 10.1 with Visual C++ Express 2008 in Release configuration.

    The error I get is the following:

    Windows has triggered a breakpoint in RF.exe.
    This may be due to a corruption of the heap, which indicates a bug in RF.exe or any of the DLLs it has loaded.
    This may also be due to the user pressing F12 while RF.exe has focus.
    The output window may have more diagnostic information.

    In Debug configuration I get:
    Debug Assertion Failed!

    Program: c:\Test\Debug\test.exe
    File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp
    Line: 52

    Expression: _BLOCK_TYPE_IS_VALID(pHeap->nBlockUse)

    For information on how your program can cause an assertion failure, see the Visual C++documentation on asserts

    I narrowed down the problem to a BranchCallback where I create a NodeData object (subclass MyNodeData) using "new (env)" instead of "new".

    NodeData* nodeData = new (env) MyNodeData();
    makeBranch(vars, bounds, dirs, objestimate, nodeData);

    If I simply use "new", I don't get any error but then there is a memory leak in the program...

    Any ideas/suggestions ? Is Visual C++ Express 2008 the problem ? Could I use Visual C++ Express 2005 instead ? Or do I absolutely have to use Visual Studio 2005 ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Memory error using Cplex 10.1

    Posted 07/09/08 10:03 PM

    Originally posted by: SystemAdmin


    [Sylvain said:]

    Some updates on my problem.
    I tryed using Visual C++ Express 2005 with Cplex 11.0 any I got the same results.
    So it doesn't seem to by an incompatibility between the different versions of Cplex and Visual C++ Express.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Memory error using Cplex 10.1

    Posted 07/09/08 11:34 PM

    Originally posted by: SystemAdmin


    [prubin said:]


    I narrowed down the problem to a BranchCallback where I create a NodeData object (subclass MyNodeData) using "new (env)" instead of "new".

    NodeData* nodeData = new (env) MyNodeData();
    makeBranch(vars, bounds, dirs, objestimate, nodeData);

    If I simply use "new", I don't get any error but then there is a memory leak in the program...


    It's been a while since I used C++ (largely because its memory handling drove me nuts), but wouldn't "new (env) MyNodeData()" be casting your node data object to ... something ... the class of "env"?

    At any rate, taking out the "(env)" strikes me as a good idea.  As far as the memory leak, I'll just hazard a guess that in MyNodeData() you create some things that take memory from the heap.  When CPLEX is done with a node, it calls the inherited destructor for the node data object ~NodeData().  I [i]think[/i] that's supposed to call default destructors on anything that's obviously a part of the MyNodeData object (members, I suppose), but if you are dynamically allocating arrays or some such, you may need to override the destructor to zap all the bits and pieces of the MyNodeData object.  (This is a major reason I switched to Java, which can usually figure out what all needs deletion when an object stops being used.)

    /Paul

    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Memory error using Cplex 10.1

    Posted 07/10/08 12:07 AM

    Originally posted by: SystemAdmin


    [Sylvain said:]

    [quote author=prubin link=topic=387.msg1103#msg1103 date=1215628461]
    It's been a while since I used C++ (largely because its memory handling drove me nuts), but wouldn't "new (env) MyNodeData()" be casting your node data object to ... something ... the class of "env"?

    I have seen it done many times (for instance in the definitions of the macros BRANCHCALLBACK0, ...) and I understand that code as creating an object using the heap of the IloEnv object env. That way the object is managed and deleted by env instead of the regular heap (or something like that).
    I don't know what is good practice but I thought this would be better...

    Concerning the memory leak I'm not quite sure where it comes from but it's not from MyNodeData destructors during which I clearly end() all the necessary members of the class.
    It could come from other part of the code though.
    #CPLEXOptimizers
    #DecisionOptimization