Forum Discussion

FICO's avatar
FICO
Community Manager
4 years ago

Memory Problem with Xpress 8.12.3 (.Net C#) on Linux Machine

Hello,

We are facing Memory Issues with Xpress when using on Linux Machine.

We are using Xpress version 8.12.3 with the .net C# interface.

When running on a windows machine memory is released and GC is collecting memory used by Xpress.

When using Linux machine memory used by Xpress is not released efficiently and we are getting memory exceptions (out of memory).

We are running multiple models in iterations. We initialize the solver once and create new models using the same solver.

Initialize code.
 
 
 
 private void InitializeOEMLicense()
 
    {
 
      int OEMval = 0;
 
      string OEMmsg = "";
 
      bool needLicense = XPRS.BeginLicensing();
 
      try
 
      {
 
        if (needLicense)
 
        {
 
          XPRS.License(ref OEMval, ref OEMmsg);
 
          OEMval = xxxxxxxxxxxxxxxxxx;
 
          if (XPRS.License(ref OEMval, ref OEMmsg))
 
          {
 
            this.logger.LogInformation(OEMmsg);
 
          }
 
          else
 
          {
 
            this.logger.LogInformation("Xpress development software detected");
 
          }
 
        }
 
        int err = XPRB.init();
 
        if (err != 0)
 
          this.logger.LogInformation("failed to initialize Xpress-BCL (code " + err + ")");
 
      }
 
      catch (XPRSException e)
 
      {
 
        this.logger.LogInformation("ERROR: Couldn’t license optimizer");
 
        this.logger.LogInformation(XPRS.GetLicErrMsg());
 
      }
 
      finally
 
      {
 
        XPRS.EndLicensing();
 
      }
 
    }
 
Release code
 
 
 
private void FreeOEMLicense()
 
    {
 
      XPRS.BeginLicensing();
 
      try
 
      {
 
        XPRB.free();
 
      }
 
      finally
 
      {
 
        XPRS.EndLicensing();
 
      }
 
    }
 
Code for creating a new model.
 
 
 
using (XPRBexprContext ctx = new XPRBexprContext())
 
      {
 
        var bclProblem = new XPRBprob(problemName);
 
        var optimizerProblem = bclProblem.getXPRSprob();
 
 
 
        .....
 
      }
 
Model Dispose code
 
 
 
protected virtual void Dispose(bool disposing)
 
    {
 
      if (this.disposed)
 
        return;
 
 
 
      if (disposing)
 
      {
 
			// Managed resources
 
        this.Variables.Clear();
 
        this.Constraints.Clear();
 
        this.Expressions.Clear();
 
        this.InitialSolVariables.Clear();
 
        this.Objective = null;
 
      }
 
			
 
			// Xpress problems
 
      this.optimizerProblem.Dispose();
 
      this.bclProblem.Dispose();
 
      this.disposed = true;
 
      this.logger.LogInformation($"Disposed model {this.ProblemName}");
 
    }

Please tell us if we are missing something.

Thanks,

Shamsher

2 Replies

  • FICO's avatar
    FICO
    Community Manager

    I don't see an obvious mistake here. Could you try to call XPRB.init()/free() in each iteration? And maybe even re-initialize the solver in every iteration? Just to see whether this fixes the memory issues.

  • FICO's avatar
    FICO
    Community Manager

    Thanks, Daniel for the reply. I will try these.