Releasing shared resources

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()

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search