Memory management
Provides information on memory management while using the OPL Java interface.
The Java garbage collector usually takes care of the memory allocated by Java objects. However, since the OPL Java API allocates memory in C++ as well, the memory management is slightly different. When you use the OPL Java API, the first object you create is always the OPL factory. Then, you use the OPL factory to create all other objects. All the C++ memory is allocated on an internal heap of the IloOplFactory object and cleaned up by a call to the method IloOPLFactory.end. The internal heap is an instance of the C++ class IloEnv.
This means that in most cases you do not need to be concerned with memory management: all the memory used by your model is correctly cleaned up at the end.
Some applications may need tighter control on memory management.
This is the case for applications to which all of the following situations apply:
They demand a lot of memory.
They make a lot of incremental model modifications: elements are repeatedly created and added to, then removed from, the model, which is solved after each addition or removal.
They are long-lived, that is, the application keeps modifying and re-solving the same model over long periods.
Such applications can explicitly manage memory by calling the method IloMPModeler.delete on Concert objects or end on OPL objects. These methods delete objects before the global cleanup and thus free memory earlier.