A deep copy duplicates an object and its reachable data, but the copying method determines its costs. JSON roundtripping creates a serialized string and then a second object graph; during parsing, both remain alive, potentially tripling the data’s memory footprint. The string can also be much larger than the original graph. section 9.4.1
Choose a copying strategy based on what must be preserved:
- Use structuredClone for deep copies that need to handle circular references, typed arrays, bigint values, or Date objects. section 9.4.1
- Extract only the needed properties when a full duplicate is unnecessary; avoiding needless copies reduces work for the garbage collector. section 9.4.1
const copy = JSON.parse(JSON.stringify(original));
JSON roundtrip deep-copy pattern. section 9.4.1
const copy = structuredClone(original);
structuredClone alternative. section 9.4.1






