ReleaseMethod

Applies to:Fast Math Parser
Class:uCalc.Item
Releases an Item defined with Define or other related function
Syntax
Release()
Remarks
When a function, operator, variable, or other item is defined with such functions as Define, DefineFunction, DefineOperator, DefineVariable, these items remain in memory, until they are released with this function. Items should generally be released when they are no longer needed, in order to preserve memory.

Note: A uCalc Item object must explicitely be released with Release unless the entire uCalc object it is a part of is is released. An Item object will not be released automatically when it simply goes out of scope.

Example 1: Displaying a different result for each value of x based on the expression parsed with Parse

Dim VariableX = uc.DefineVariable("x")
Dim Expression As string
Console.Write("Enter an expression (Ex: x^2 * 10): ")
Expression = Console.ReadLine()

Dim ParsedExpr = uc.Parse(Expression)

Dim x As double
for x = 1 To 10
   VariableX.SetVariableValue(x)
   Console.WriteLine("x = " + x + "  Result = " + ParsedExpr.Evaluate())
Next

' Output
' x = 1  Result = 10
' x = 2  Result = 40
' x = 3  Result = 90
' x = 4  Result = 160
' x = 5  Result = 250
' x = 6  Result = 360
' x = 7  Result = 490
' x = 8  Result = 640
' x = 9  Result = 810
' x = 10  Result = 1000

ParsedExpr.Release()
VariableX.Release()

          

var VariableX = uc.DefineVariable("x");
string Expression;
Console.Write("Enter an expression (Ex: x^2 * 10): ");
Expression = Console.ReadLine();

var ParsedExpr = uc.Parse(Expression);

for (double x = 1; x <= 10; x = x + 1) {
   VariableX.SetVariableValue(x);
   Console.WriteLine("x = " + x + "  Result = " + ParsedExpr.Evaluate());
}

// Output
// x = 1  Result = 10
// x = 2  Result = 40
// x = 3  Result = 90
// x = 4  Result = 160
// x = 5  Result = 250
// x = 6  Result = 360
// x = 7  Result = 490
// x = 8  Result = 640
// x = 9  Result = 810
// x = 10  Result = 1000

ParsedExpr.Release();
VariableX.Release();

          

//var VariableX = uc.DefineVariable('x');
      Write('Enter an expression (Ex: x^2 * 10): ')
Expression = ReadLn();

//var ParsedExpr = uc.Parse(Expression);

      for x := 1 to 10 do
begin
   VariableX.SetVariableValue(x);
         WriteLn('x = ' + x + '  Result = ' + ParsedExpr.Evaluate());
End;

      // Output
// x = 1  Result = 10
// x = 2  Result = 40
// x = 3  Result = 90
// x = 4  Result = 160
// x = 5  Result = 250
// x = 6  Result = 360
// x = 7  Result = 490
// x = 8  Result = 640
// x = 9  Result = 810
// x = 10  Result = 1000

      ParsedExpr.Release();
      VariableX.Release();

          

auto VariableX = uc.DefineVariable("x");
string Expression;      
cout << "Enter an expression (Ex: x^2 * 10): " << endl;
cin >> Expression; // Ex: x^2 * 10

auto ParsedExpr = uc.Parse(Expression);

for (double x = 1; x <= 10; x = x + 1) {
   VariableX.SetVariableValue(x);
   cout << "x = " << x << "  Result = " << ParsedExpr.Evaluate() << endl;
}

// Output
// x = 1  Result = 10
// x = 2  Result = 40
// x = 3  Result = 90
// x = 4  Result = 160
// x = 5  Result = 250
// x = 6  Result = 360
// x = 7  Result = 490
// x = 8  Result = 640
// x = 9  Result = 810
// x = 10  Result = 1000

ParsedExpr.Release();
VariableX.Release();

          

auto VariableX = uc.DefineVariable("x");
string ^ Expression;
Console::Write("Enter an expression (Ex: x^2 * 10): ");
Expression = Console::ReadLine();

auto ParsedExpr = uc.Parse(Expression);

for (double x = 1; x <= 10; x = x + 1) {
   VariableX.SetVariableValue(x);
   Console::WriteLine("x = " + x + "  Result = " + ParsedExpr.Evaluate());
}

// Output
// x = 1  Result = 10
// x = 2  Result = 40
// x = 3  Result = 90
// x = 4  Result = 160
// x = 5  Result = 250
// x = 6  Result = 360
// x = 7  Result = 490
// x = 8  Result = 640
// x = 9  Result = 810
// x = 10  Result = 1000

ParsedExpr.Release();
VariableX.Release();

          
See also
Prev | Next