LocalSolver logo
is now
Hexaly logo

We're excited to share that we are moving forward. We're leaving behind the LocalSolver brand and transitioning to our new identity: Hexaly. This represents a leap forward in our mission to enable every organization to make better decisions faster when faced with operational and strategic challenges.


LSPReferenceScope Class

class localsolver.modeler.LSPReferenceScope

A LSPReferenceScope contains a collection of references that can be released together. It simplifies the memory management of objects returned from the modeler API.

When you access a modeler object from the C# API, your C# program takes a new reference to that modeler object. These references are automatically deleted when the associated LSPModeler object is destroyed. But in the meantime references can prevent objects from being freed even if they are no longer used in the modeler. This is especially true if the interactions between the modeler and your LSP programs are complex and are not limited to a few exchanges at the beginning/end of the resolution.

In this case, a LSPReferenceScope allows you to limit the life of your references and can help you to preserve memory.

Since:

11.5

Summary

Methods

Dispose

Releases all references associated with this scope.

Instance methods

LSPReferenceScope(LSPModeler modeler)

Creates a new LSPReferenceScope object associated with the modeler in parameter. All references created from that point anywhere in the API will be automatically associated with this new scope. All these references can then be released in one call to LSPReferenceScope.Dispose (or with a using statement).

Arguments:

modeler – The associated modeler.

void Dispose()

Releases all references associated with this scope. It is also disassociated from the modeler and the previous scope is restored as the current one. If the scope has already been disposed then this method does nothing and returns immediately.

Note: Releasing a reference does not necessarily imply that the underlying modeler object is destroyed. It is only destroyed if no more references point to it.