In most of the previous
examples, an environment is using a shared resource (e.g., a token
license, a remote machine, etc.), and as long as the environment
persists in memory, these resources remain locked, and unavailable to
other users.
To give back these shared resources you need to dispose of any model
associated with the environment, and then you need to dispose of the
environment itself.
The actual steps depend on the API you are using:
- C
- Call GRBfreemodel() for each model, then call
GRBfreeenv() for the Gurobi environment. For the previous
example, it would look like:
QUIT:
/* Clean up model and environment */
GRBfreemodel(model);
GRBfreeenv(env);
return error;
- C++
- If you use pointers to GRBModel and GRBEnv objects, delete all GRBModel objects, then delete
the GRBEnv object.
- Java
- Call GRBModel.dispose() on all GRBModel objects, then call GRBEnv.dispose() on the
GRBEnv object. For the previous example, it would look
like:
// Clean up model and environment
model.dispose()
env.dispose()
- .NET
- Call GRBModel.Dispose() on all GRBModel objects, then call GRBEnv.Dispose() on the
GRBEnv object.
- Python
- Call Model.dispose() on all Model objects, Env.dispose() on all Env
objects (if used), then call disposeDefaultEnv(). For the
previous example, it would look like:
# Clean up model and environment
model.dispose()
env.dispose()
gp.disposeDefaultEnv()