circular reference
When objects refer to each other in a loop, such as a parent pointing to a child that points back to the parent.
In more detail
A DOM element that points to its parent, which lists it as a child, is a common example. JSON.stringify throws on them; structuredClone and mark-and-sweep garbage collection both handle them correctly.
Related terms
- structured clone algorithm — The standard JavaScript algorithm for deep-copying values between threads and into storage, which handles Maps, Sets, Dates, typed arrays and circular references.
- JSON.stringify() — The JavaScript function that converts a value into a JSON string; JSON.parse() converts the string back.
- mark-and-sweep — The garbage collection method that marks every object reachable from the roots, then sweeps away everything unmarked.
Taught in
- Web Workers: Off-Thread Computation And Structured Clone — Frontend Architecture & Web Platform