reference equality
Comparing two references to see whether they point to the very same object, rather than to objects with equal contents.
In more detail
Two separately created objects with identical contents are equal by value but not by reference. Many languages compare objects by reference by default, and libraries such as React use reference equality to decide whether something changed, so a new object with the same contents counts as a change.
Examples
C#: object.ReferenceEquals(a, b)Java: == compares references for objects; use equals for content, as in "a".equals(text).React relies on reference equality for state, props, context values and dependency arrays; useMemo, useCallback and state setters help keep references stable.Related terms
- value equality — Treating two objects as equal when their members hold equal values, even if they are separate objects.
- GetHashCode — The method that returns a number summarising an object, used by hash-based collections such as Dictionary and HashSet to find it quickly.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
- equals method — The method that decides whether two objects hold the same value, as opposed to == which checks whether they are the same object.
- reference type — A type whose variables hold a reference, a pointer to an object stored elsewhere, rather than the value itself.
- Object.is — The JavaScript function that tells whether two values are the same value, comparing objects by identity.
- shallow comparison — Comparing two objects one property at a time with Object.is, without looking inside nested objects.
- useMemo — The React hook that caches the result of a calculation between renders and recalculates only when its dependencies change.
- useCallback — The React hook that returns the same function object between renders until one of its dependencies changes.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices
- Primitive And Reference Types — Modern Java: Virtual Threads & High-Throughput Services
- Fifty Items, Five Traps — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Strings, StringBuilder And Text Blocks — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Enums With Fields, Constructors And Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- State with useState: Immutability And Asynchronous Batching — React 19 & Modern Component Architecture
- Complex State with useReducer: State Machines And Action Types — React 19 & Modern Component Architecture
- useRef Mechanics: DOM References And Mutable Persistent State — React 19 & Modern Component Architecture
- Custom Hook Composition: Encapsulating Reactive Logic — React 19 & Modern Component Architecture
- useSyncExternalStore: Tearing-Free Store Subscriptions — React 19 & Modern Component Architecture
- React.memo, useMemo, And useCallback: Optimization Costs — React 19 & Modern Component Architecture
References
- Equality comparisons
- Java Language Specification, chapter 15: Expressions
- MDN: Equality comparisons and sameness
- React reference: useMemo, skipping re-rendering