Originally posted by: Erebos
Hi all,
I experience run-time access violations seemingly caused by out-of-memory when I use CPLEX repeatedley to solve MIP problems. I use the CPLEX 12.5 concert API with Visual Studio C++ 2012.
The following procedure is applied many times. I myself do not construct object in the heap (new). The pseudo code of the function is:
void testCplex() {
IloEnv env;
IloModel model(env);
IloExpr obj(env);
IloIntVarArray x(env);
IloIntVarArray y(env);
while (condition) {
....
x.add(IloIntVar(env, 0, 1));
}
while (condition) {
...
y.add(IloIntVar(env, 0, 1));
if (q >= x.getSize()) throw string("q >= x-size");
if (r >= x.getSize()) throw string("r >= x-size");
if (p >= y.getSize()) throw string("p >= y-size");
model.add( x[q] + x[r] <= 1 + y[p] );
obj += y[p] * 1.;
}
while (condition) {
IloExpr flowSum(env); // Temporary IloExpr ok?
.......
model.add (flowSum == 1.);
}
...
model.add(IloMinimize(env, obj));
obj.end();
IloCplex cplex(env); // run-time access violation here!
....
}
Call stack after crash is:
test.exe!IloCplexCache::finitCache(class IloCplexCache * &) C++
test.exe!IloCplexI::clear(void) C++
test.exe!IloCplexI::~IloCplexI(void) C++
test.exe!IloCplexI::`vector deleting destructor'(unsigned int) C++
test.exe!IloAlgorithm::end(void) Unknown
test.exe!IloCplex::construct(class IloEnv,bool,struct cpxenv * (*)(char const *,int,char const * const *,int *),char const *,int,char const * const *,void const *) C++
disassembly:
00655764 ret
00655765 test ecx,ecx
00655767 je IloCplexCache::finitCache+2Fh (065576Fh)
00655769 mov eax,dword ptr [ecx]
0065576B push 1
0065576D call dword ptr [eax]
0065576F push esi
00655770 call dword ptr ds:[0A1A93Ch]
00655776 mov dword ptr [esi],0
The crash is at 00655767: "Unhandled exception at 0x00655769 in test.exe: 0xC0000005: Access violation reading location 0xFEEEFEEE."
First question: I generate an all-integer model. However, I always see a single linear variable fixed at zero in the model which I did not add at all. This is an enigma to me. How can this be explained?
Second question: I figured out that I run out of memory (> 2GB for 32bit processes). Over the time the memory usage increases until it reaches the 2GB limit which then at the 347th model results in the crash.
It appears to me that the destructors of all the IloXXXobjects won't free all the memory. Is this true? How can I free all the memory used by CPLEX?
Kind regards
#CPLEXOptimizers#DecisionOptimization