uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026

Warning

uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.

MemoryIndex = [int]

Property

Product: 

Class: 

Returns a stable, predictable integer index for the expression object, useful for diagnostics and tracking object lifetime.

Remarks

The MemoryIndex method returns a stable, predictable integer identifier for a specific Expression object. While primarily intended for diagnostics and internal use, it provides a reliable way to track individual objects throughout their lifecycle.

⚖️ MemoryIndex vs. Handle

It's crucial to distinguish MemoryIndex from an object's Handle:

FeatureMemoryIndexHandle
StabilityStable & Predictable. The first object gets index 1, the second gets 2, etc.Volatile. An internal pointer-like value that changes between application runs.
UniquenessUnique for the object's lifetime, but can be recycled after release.Guaranteed unique for the object's lifetime.
PurposeHigh-level diagnostics, logging, and tracking object lifetimes.Low-level internal operations.

♻️ Index Recycling

When an Expression object is released using Release, its MemoryIndex is returned to a pool. The next Expression object created will reuse that index. This is an efficient memory management strategy, but it means you cannot assume that a given index refers to the same logical expression for the entire duration of your application's run. If you need to track objects, you must also track their creation and destruction.

💡 Comparative Analysis

In standard C# or C++, developers often rely on object references or pointers to identify objects. If you need a stable integer ID, you typically have to add it yourself, often with a static counter.

// Manual C# approachpublic class MyObject {    private static int nextId = 0;    public int Id { get; private set; }    public MyObject() {        this.Id = System.Threading.Interlocked.Increment(ref nextId);    }}

uCalc provides this functionality out-of-the-box with MemoryIndex. Its built-in recycling mechanism is a performance optimization that manual implementations often overlook. This makes MemoryIndex a valuable tool for advanced users building performance-sensitive applications or debugging complex object interactions.

Examples