ReleaseMethod

Applies to:Fast Math Parser
Class:uCalc.ParsedExpr
Releases an expression that was parsed with Parse
Syntax
Release()
Remarks
Whenever an expression is parsed with Parse, the parsed expression remains in memory until released. When the parsed expression is no longer needed it should be released with Release to preserve memory. Note: An expression parsed with Parse must explicitely be released with Release unless the uCalc object it is in is released. A parsed expression 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